Page 1 of 1

รบกวนท่านผู้รู้แก้คำสั่ง VBA ใน word นี้ให้หน่อยครับ

Posted: Wed Jun 19, 2019 3:47 am
by NopadoN
ตามรูปตัวอย่าง : ถ้ารัน VBA ตามคำสั่งปัจจุบัน จะได้ชื่อไฟล์อยู่ด้านล่างรูปภาพ แต่ที่ต้องการ จะให้ชื่อไฟล์อยู่ด้านบนรูปภาพด้านขวา และตัดตัวอักษร "JPG" ออกครับ

คำสั่ง VBA
Sub PicWithCaption()
Dim xFileDialog As FileDialog
Dim xPath, xFile As Variant
On Error Resume Next
Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
If xFileDialog.Show = -1 Then
xPath = xFileDialog.SelectedItems.Item(1)
If xPath <> "" Then
xFile = Dir(xPath & "\*.*")
Do While xFile <> ""
If UCase(Right(xFile, 3)) = "PNG" Or _
UCase(Right(xFile, 3)) = "TIF" Or _
UCase(Right(xFile, 3)) = "JPG" Or _
UCase(Right(xFile, 3)) = "GIF" Or _
UCase(Right(xFile, 3)) = "BMP" Then
With Selection
.InlineShapes.AddPicture xPath & "\" & xFile, False, True
.InsertAfter vbCrLf
.MoveDown wdLine
.Text = xFile & Chr(10)
.MoveDown wdLine
End With
End If
xFile = Dir()
Loop
End If
End If
ขอบคุณครับ

Re: รบกวนท่านผู้รู้แก้คำสั่ง VBA ใน word นี้ให้หน่อยครับ

Posted: Wed Jun 19, 2019 6:04 pm
by snasui
:D กรุณาแนบไฟล์ตัวอย่างที่เขียน Code นี้ไว้แล้วมาด้วยจะได้ช่วยดูต่อไปจากนั้นครับ

สำหรับการ Post Code ให้แสดงในรูปแบบของ Code ดูตัวอย่างจากกฎการใช้บอร์ดข้อ 5 ด้านบนครับ :roll: