文章目录
1.打开一个需要插入的word2.打开Word VBA3.点击ThisDocument4.粘贴代码进去,然后关闭(复制代码,别手敲!!!)5.点击运行宏6.选择要插入的图片目录7.大功告成1.打开一个需要插入的word
2.打开Word VBA
快捷键:Alt+F11
3.点击ThisDocument
4.粘贴代码进去,然后关闭(复制代码,别手敲!!!)
Sub PicWithCaption()Dim xFileDialog As FileDialogDim xPath, xFile As VariantDim indexindex = index + 1On Error Resume NextSet xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)If xFileDialog.Show = -1 ThenxPath = xFileDialog.SelectedItems.Item(1)If xPath <> "" ThenxFile = 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" ThenWith Selection.InlineShapes.AddPicture xPath & "\" & xFile, False, True.InsertAfter vbCrLf.MoveDown wdLine.Text = "图" & index & "-" & xFile.MoveDown wdLine.MoveDown wdLineindex = index + 1End WithEnd IfxFile = Dir()LoopEnd IfEnd IfEnd Sub
5.点击运行宏
快捷键:F5