【问题标题】:replace text in multiple footer and/or primary footer word vba替换多个页脚和/或主要页脚单词 vba 中的文本
【发布时间】:2015-03-07 03:46:49
【问题描述】:

我想替换 word doc 页脚中的文本。有些文档可能只有主页眉和页脚,有些文档有多个页眉和页脚。

这是我的代码:

Sub changedate()

     Selection.HomeKey Unit:=wdStory
     ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter    

Check1:
     With Selection.Find
        .Text = "Dec 01, 2015"
        .Replacement.Text = "Dec 01, 2015"
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

      ActiveWindow.ActivePane.View.NextHeaderFooter
    On Error GoTo Cont
         GoTo Check1


Cont:
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument


End Sub

在多个页脚文档上它可以正常工作,但如果只有一个页脚可用,则会显示错误。

【问题讨论】:

  • 出现什么错误?

标签: vba ms-word


【解决方案1】:

您需要在代码中将On Error 向上移动一行。否则,当您查找下一个页脚时,找不到任何页脚,并且在代码读取有关如何处理错误的行之前发生错误。

编辑:您也可以使用For Each wdPrimaryFooterStory in ActiveDocument.StoryRanges(不确定确切的语法,但这应该会有所帮助:http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm

【讨论】:

    猜你喜欢
    • 2020-05-21
    • 2021-03-13
    • 2015-07-09
    • 2019-08-27
    • 2019-07-04
    • 1970-01-01
    • 2017-09-25
    • 2019-05-20
    • 2018-02-12
    相关资源
    最近更新 更多