从Excel VBA在Word中添加页脚

问题描述

我正在尝试使用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,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

但是我找不到问题。我能做什么?我希望你能帮助我。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)