|
楼主 |
发表于 2020-11-24 17:11
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
请问运行到.tables(1).cell(1, 5).Range.InlineShapes.AddPicture Filename:=p出错是怎么回事?
运行错误5152,应用程序定义或对象定义错误
------------------------------------------------
Sub 插入()
Application.ScreenUpdating = False
Dim f, p, s
Set word = VBA.CreateObject("word.application")
word.Visible = True
f = Dir(ThisWorkbook.Path & "\*.docx")
Do While f <> ""
With word.documents.Open(ThisWorkbook.Path & "\" & f)
s = Replace(Replace(.tables(1).cell(1, 2).Range, "□", ""), Chr(13), "")
p = ThisWorkbook.Path & "\照片\" & s & ".png"
.tables(1).cell(1, 5).Range = ""
.tables(1).cell(1, 5).Range.InlineShapes.AddPicture Filename:=p, linktofile:=False, savewithdocument:=True
.Close True
End With
f = Dir
Loop
word.Quit
MsgBox "ok"
End Sub
|
|