标题: [文件操作] 如何批量将文件夹内的图片导入word文档? [打印本页]
作者: xiawj 时间: 2022-9-6 15:22 标题: 如何批量将文件夹内的图片导入word文档?
如何批量将文件夹内的图片导入word文档? 如:A文件夹内有多张jpg文件和一个word文件,如何批量操作将该文件夹内的所有jpg文件插入word文档
作者: hfxiang 时间: 2022-9-6 16:12
- Sub 批量插入图片()
- Dim myfile As FileDialog
- Set myfile = Application.FileDialog(msoFileDialogFilePicker)
- Application.ScreenUpdating = False
- With myfile
- .InitialFileName = "D:\PicDir"
- If .Show = -1 Then
- For Each Fn In .SelectedItems
- Selection.Text = Basename(Fn)
- Selection.EndKey
- If Selection.Start = ActiveDocument.Content.End - 1 Then
- Selection.TypeParagraph
- Else
- Selection.MoveDown
- End If
- Set mypic = Selection.InlineShapes.AddPicture(FileName:=Fn, SaveWithDocument:=True)
- If Selection.Start = ActiveDocument.Content.End - 1 Then
- Selection.TypeParagraph
- Selection.TypeParagraph
- Else
- Selection.MoveDown
- End If
- Next Fn
- Else
- End If
- End With
- Set myfile = Nothing
- Application.ScreenUpdating = True
- End Sub
- Function Basename(FullPath)
- Dim x, y
- Dim tmpstring
- tmpstring = FullPath
- x = Len(FullPath)
- For y = x To 1 Step -1
- If Mid(FullPath, y, 1) = "\" Or _
- Mid(FullPath, y, 1) = ":" Or _
- Mid(FullPath, y, 1) = "/" Then
- tmpstring = Mid(FullPath, y + 1)
- Exit For
- End If
- Next
- Basename = Left(tmpstring, Len(tmpstring) - 4)
- End Function
复制代码
作者: xiawj 时间: 2022-9-6 17:04
回复 2# hfxiang 怎么用?
作者: Batcher 时间: 2022-9-6 17:11
回复 1# xiawj
这个方法可以吗
https://jingyan.baidu.com/article/6525d4b1603762ed7d2e94ea.html
作者: hfxiang 时间: 2022-9-6 18:57
回复 3# xiawj
先打开word,之后Alt+F11->{插入->模块->[编辑:Ctrl+C & Ctrl+V]->Ctrl+s}->Alt+F8
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |