|
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 = 1
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
修改食用... |
|