【发布时间】:2020-12-24 04:46:25
【问题描述】:
我正在尝试使用 Vba 在 Excel 工作簿中的 Word 文件中插入一些文本。这是我拥有的代码的一部分:
fileRow = Range("AE101").Value
fileLocation = Range("AE" & filaActa).Value
Set WordDoc = CreateObject("Word.Application")
WordDoc.DisplayAlerts = False
WordDoc.Visible = True
Set WordApp = WordDoc.Documents.Open(Filename:=File, ReadOnly:=False)
这是我尝试的最后一个代码,但我不断收到相同的错误:
With WordApp.Sections(1).Footers(wdHeaderFooterPrimary).Range
.InsertAfter Text:="Printed: "
.Fields.Add .Characters.Last, wdFieldEmpty, "This is a Footer", False
.InsertAfter vbTab
.InsertAfter vbTab
.InsertAfter Text:="Page "
.Fields.Add Range:=.Characters.Last, Type:=wdFieldEmpty, Text:="PAGE", PreserveFormatting:=False
.InsertAfter Text:=" of "
.Fields.Add Range:=.Characters.Last, Type:=wdFieldEmpty, Text:="NUMPAGES", PreserveFormatting:=False
End With
当我运行它时,我得到了错误; "运行时错误 '5941' 请求的集合成员不存在"
我已经尝试在这两个解决方案中做同样的事情:
Microsoft Word VBA to insert footer from excel
Find and Replace footer text in Word with an Excel VBA Macro
但我找不到问题所在。我能做些什么?我希望你能帮助我。
【问题讨论】:
标签: excel vba ms-word header footer