|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 约定的童话 于 2020-8-28 14:00 编辑
这个难度不小啊......
Sub VBA批量插入图片到Word()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim i, m As String, arr, Word As Object, F
Set Word = VBA.CreateObject("word.application")
Word.Visible = 0
F = Dir(ThisWorkbook.Path & "\" & "*.doc")
Do While F <> ""
Set MyWord = Word.Documents.Open(ThisWorkbook.Path & "\" & F)
For n = 4 To 7 '根据word实际表格来
m = Replace(Replace(Replace(Split(MyWord.Tables(n).Cell(2, 1).Range, ":")(1), "", ""), " ", ""), Chr(13), "") '提取图片名称
t = ThisWorkbook.Path & "\图片\" & m & ".jpg" '获得图片路径
MyWord.Tables(n).Cell(1, 1).Range.InlineShapes.AddPicture Filename:=t, LinkToFile:=False, SaveWithDocument:=True '直接插入 Myword.InlineShapes(n - 3).Height = 280 '调整图片高度
Next
Word.Documents.Close True
F = Dir
Loop
Word.Application.Quit
Set MyWord = Nothing
MsgBox "插入完毕!", 48, "提示!"
End Sub
|
评分
-
2
查看全部评分
-
|