ไปยังเนื้อหาหลัก

จะแทรกรูปภาพหลายรูปพร้อมชื่อไฟล์ในเอกสาร Word ได้อย่างไร?

ในเอกสาร Word คุณสามารถแทรกรูปภาพหลายภาพพร้อมกันได้อย่างรวดเร็วโดยใช้ฟังก์ชันแทรก แต่บางครั้งคุณต้องแทรกเส้นทางไฟล์และชื่อเป็นคำอธิบายภาพเมื่อแทรกรูปภาพ คุณจะจัดการกับงานนี้ในไฟล์ Word ได้อย่างไร?

แทรกรูปภาพหลายรูปพร้อมชื่อไฟล์โดยใช้รหัส VBA

แทรกรูปภาพหลายรูปพร้อมชื่อไฟล์โดยใช้ Kutools for Word


แทรกรูปภาพหลายรูปพร้อมชื่อไฟล์โดยใช้รหัส VBA

รหัส VBA ต่อไปนี้สามารถช่วยคุณในการแทรกเส้นทางของไฟล์และตั้งชื่อเป็นคำอธิบายภาพเมื่อแทรกรูปภาพได้โปรดทำดังนี้:

1. กด ALT + F11 คีย์เพื่อเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

2. จากนั้นคลิก สิ่งที่ใส่เข้าไป > โมดูลคัดลอกและวางโค้ดด้านล่างลงในโมดูลเปล่าที่เปิดอยู่:

รหัส 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 = xPath & "\" & xFile & Chr(10)
                        .MoveDown wdLine
                    End With
                End If
                xFile = Dir()
            Loop
        End If
    End If
End Sub

3. จากนั้นกด F5 คีย์เพื่อเรียกใช้รหัสนี้หน้าต่างเรียกดูจะปรากฏขึ้นโปรดเลือกโฟลเดอร์ที่มีภาพที่คุณต้องการแทรกดูภาพหน้าจอ:

doc แทรกภาพด้วยชื่อไฟล์ 1

4. จากนั้นคลิก OK รูปภาพทั้งหมดในโฟลเดอร์ที่เลือกได้ถูกแทรกลงในเอกสาร Word และเส้นทางของไฟล์และชื่อถูกแทรกเป็นคำอธิบายภาพดูภาพหน้าจอ:

doc แทรกภาพด้วยชื่อไฟล์ 2


แทรกรูปภาพหลายรูปพร้อมชื่อไฟล์โดยใช้ Kutools for Word

ถ้าคุณมี Kutools สำหรับ Wordเดียวกันกับที่ ภาพ คุณสามารถแทรกรูปภาพหลาย ๆ รูปได้อย่างรวดเร็วด้วยเส้นทางไฟล์และชื่อลงในเอกสาร Word ได้ทันที

Kutools สำหรับ Word : ด้วยโปรแกรมเสริม Word ที่มีประโยชน์มากกว่า 100 รายการให้ทดลองใช้ฟรีโดยไม่มีข้อ จำกัด ใน 60 วัน. 

หลังจากการติดตั้ง Kutools สำหรับ Wordโปรดทำตามนี้:

1. คลิก Kutools > ภาพดูภาพหน้าจอ:

doc แทรกภาพด้วยชื่อไฟล์ 3

2. ในการโผล่ออกมา แทรกรูปภาพ โปรดดำเนินการด้านล่าง:

  • (1. ) คลิก เพิ่มไฟล์ or เพิ่มโฟลเดอร์ ปุ่มเพื่อเลือกภาพที่คุณต้องการแทรก
  • (2. ) จากนั้นตรวจสอบ แทรกเส้นทางไฟล์ของแต่ละภาพเป็นคำบรรยาย ตัวเลือกที่ด้านล่างซ้ายของกล่องโต้ตอบ
  • (3. ) จากนั้นคลิก สิ่งที่ใส่เข้าไป ปุ่ม

doc แทรกภาพด้วยชื่อไฟล์ 4

3. หลังจากแทรกภาพแล้วคุณจะเห็นเส้นทางไฟล์ของแต่ละภาพและมีการแทรกชื่อเช่นกันดูภาพหน้าจอ:

doc แทรกภาพด้วยชื่อไฟล์ 5

คลิกเพื่อดาวน์โหลด Kutools for Word และทดลองใช้ฟรีทันที!

สุดยอดเครื่องมือเพิ่มผลผลิตในสำนักงาน

Kutools สำหรับ Word - ยกระดับประสบการณ์คำศัพท์ของคุณด้วย Over 100 คุณสมบัติเด่น!

🤖 Kutools ผู้ช่วย AI: แปลงโฉมงานเขียนของคุณด้วย AI - สร้างเนื้อหา  /  เขียนข้อความใหม่  /  สรุปเอกสาร  /  สอบถามข้อมูล ขึ้นอยู่กับเอกสารทั้งหมดนี้ภายใน Word

📘 ความเชี่ยวชาญด้านเอกสาร: แยกหน้า  /  ผสานเอกสาร  /  ส่งออกตัวเลือกในรูปแบบต่างๆ (PDF/TXT/DOC/HTML...)  /  แบทช์แปลงเป็น PDF  /  ส่งออกเพจเป็นรูปภาพ  /  พิมพ์หลายไฟล์พร้อมกัน...

การแก้ไขเนื้อหา: ค้นหาแบทช์และแทนที่ ข้ามหลายไฟล์  /  ปรับขนาดรูปภาพทั้งหมด  /  ย้ายแถวและคอลัมน์ของตาราง  /  แปลงตารางเป็นข้อความ...

🧹 ทำความสะอาดได้อย่างง่ายดาย: หลบไป พื้นที่พิเศษ  /  แบ่งส่วน  /  ส่วนหัวทั้งหมด  /  กล่องข้อความ  /  เชื่อมโยงหลายมิติ  / หากต้องการดูเครื่องมือถอดเพิ่มเติม โปรดไปที่ของเรา ลบกลุ่ม...

ส่วนแทรกโฆษณา: แทรก ตัวคั่นหลักพัน  /  กล่องกาเครื่องหมาย  /  ปุ่มวิทยุ  /  คิวอาร์โค้ด  /  บาร์โค้ด  /  ตารางเส้นทแยงมุม  /  คำอธิบายสมการ  /  คำบรรยายภาพ  /  คำบรรยายตาราง  /  รูปภาพหลายภาพ  / ค้นพบเพิ่มเติมใน แทรกกลุ่ม...

🔍 การเลือกที่แม่นยำ: ระบุ หน้าที่เฉพาะเจาะจง  /  ตาราง  /  รูปร่าง  /  หัวเรื่องย่อหน้า  / เสริมการนำทางด้วย ข้อมูลเพิ่มเติม เลือกคุณสมบัติ...

การปรับปรุงดาว: นำทางอย่างรวดเร็วไปยังสถานที่ใด ๆ  /  แทรกข้อความซ้ำอัตโนมัติ  /  สลับระหว่างหน้าต่างเอกสารได้อย่างราบรื่น  /  11 เครื่องมือการแปลง...

???? ต้องการลองใช้คุณสมบัติเหล่านี้หรือไม่? Kutools for Word มีไฟล์ ทดลองใช้ฟรี 60 วันโดยไม่มีข้อจำกัด! 🚀
 
Comments (11)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
VBA CODE IS VERY USEFULLY MY DATA VALIDATE IMAGES SHARING.
This comment was minimized by the moderator on the site
How can I decrease the overall size of the photo so there are multiple per page?
This comment was minimized by the moderator on the site
Is there a way to insert each picture and file name per page? Sometimes if one picture is too big the file name will then go to the next page or if picture is too small the next picture will be together in one page instead on the next page
This comment was minimized by the moderator on the site
Hello, Rizza,
To insert each picture and file name per page, please apply the following vba code:
Sub PicWithCaption()
    Dim xFileDialog As FileDialog
    Dim xPath As String, xFile As String
    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
                    
                    ' Add the picture
                    Selection.InlineShapes.AddPicture xPath & "\" & xFile, False, True
                    Selection.TypeParagraph
                    
                    ' Add the file path below the picture
                    Selection.TypeText xPath & "\" & xFile
                    Selection.TypeParagraph
                    
                    ' Move to the next page
                    Selection.InsertBreak Type:=wdPageBreak
                End If
                xFile = Dir()
            Loop
        End If
    End If
End Sub


Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
A problem occurs when the file name to be added exceeds 10.

pic1
pic10
pic11
pic12
pic2
pic3
pic4
pic5...
This comment was minimized by the moderator on the site
change the file name to 01, 02, 03 and it will work
This comment was minimized by the moderator on the site
Wow this is great! I only needed the file name, so I deleted "xPath & "\" &" from the .Text line and that worked perfectly. Thanks for this!
This comment was minimized by the moderator on the site
Which line of code would you change and how to have the file path written before the picture, aka the caption (filename) is above rather than below.
This comment was minimized by the moderator on the site
With Selection
.Text = xFile
.InlineShapes.AddPicture xPath & "\" & xFile, False, True
.InsertAfter vbCrLf
.MoveDown wdLine

End With
This comment was minimized by the moderator on the site
Have to add this .MoveDown wdLine after .Text=xFile
This comment was minimized by the moderator on the site
buenas noches amigo me ha servido mucho su información sinembargo me surge una duda cree que es posible incertar imagenes en word de la misma manera pero dentro de celdas incertadas?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations