更改部分代码后,我在 Excel 中收到错误“对象不支持此属性或方法” 。引发错误的行是“With odoc.MailMerge”这是代码:
strBookName = "\" & "PM MailMerge.xlsm"
strBookPath = ActiveWorkbook.Path
strBook = strBookPath & strBookName
'Opens Word.Application
Set ObjWord = CreateObject("Word.Application")
Set odoc = GetObject(strBook)
'Executes a Hidden Mail Merge
ObjWord.Visible = False
With odoc.MailMerge
.Destination = wdSendToNewDocument
With .DataSource
.FirstRecord = 1
.LastRecord = 1
odoc.MailMerge.Execute
Set odoc2 = odoc.Application.documents("Form Letters1")
odoc.Close True
End With
End With