1.打开一个需要插入的word

2.打开Word VBA
快捷键:Alt + F11

3.点击ThisDocument

4.粘贴代码进去,然后关闭(复制代码,别手敲!!!)
Sub PicWithCaption()
Dim xFileDialog As FileDialog
Dim xPath, xFile As Variant
Dim index
index = index + 1
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 = "图" & index & "-" & xFile
.MoveDown wdLine
.MoveDown wdLine
index = index + 1
End With
End If
xFile = Dir()
Loop
End If
End If
End Sub
5.点击运行宏

快捷键:F5
6.选择要插入的图片目录

7.大功告成

该博客介绍了如何通过Word的VBA宏来自动化插入图片。步骤包括打开VBA编辑器,创建宏,粘贴代码,运行宏选择图片目录,最终实现批量插入指定文件夹内的图片,并自动添加图片编号和描述。
2008

被折叠的 条评论
为什么被折叠?



