【问题标题】:word 2010 footer change text from second pageword 2010 页脚从第二页更改文本
【发布时间】:2021-10-03 21:46:05
【问题描述】:

我像这样搜索和更改页脚中的文本:

Sub 123()
    Dim xDoc As Document
    Dim xSelection As Selection
    Dim xSec As Section
    Dim xHeader As HeaderFooter
  Dim xFooter As HeaderFooter
On Error Resume Next
    Set xDoc = Application.ActiveDocument
    For Each xSec In xDoc.Sections
          For Each xFooter In xSec.Footers
            xFooter.Range.Select
            Set xSelection = xDoc.Application.Selection
            With xSelection.Find
                .Text = "text1"
                .Replacement.Text = "text2"
                .Wrap = wdFindContinue
                .Execute Replace:=wdReplaceAll
            End With
        Next xFooter
    Next xSec
    xDoc.ActiveWindow.ActivePane.Close
    If xDoc.ActiveWindow.View.SplitSpecial = wdPaneNone Then
        xDoc.ActiveWindow.View.Type = wdPrintView
    Else
        xDoc.ActiveWindow.View.Type = wdPrintView
    End If
    xDoc.Activate
End Sub

宏运行后,第一页会添加几个空行。如何使宏从文档的第二页开始工作?

更新: 我错误地描述了这个问题,它没有创建行,它添加了一个空标题。

更新 2:

我借助代码解决了问题:

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter

【问题讨论】:

  • 首先,在 VBA 中处理文档时,很少需要选择任何内容,当然也没有必要这样做。其次,Word 文档的每个范围,包括页眉和页脚,都至少包含一个段落。
  • 您需要更改的是主页脚或偶数页页脚。 Word 中的每个部分都可以包含三个页脚。 addbalance.com/usersguide/sections2007.htm#Recap_of_Header/…

标签: vba ms-word word-2010


【解决方案1】:

试试下面的代码:

Sub abc()
    Dim xDoc As Document
    Dim xSec As Section
    Dim xHeader As HeaderFooter
    Dim xFooter As HeaderFooter
    On Error Resume Next
    Set xDoc = Application.ActiveDocument
    For Each xSec In xDoc.Sections
        For Each xFooter In xSec.Footers
            If xFooter.Exists Then
                With xFooter.Range.Find
                    .Text = "text1"
                    .Replacement.Text = "text2"
                    .Wrap = wdFindContinue
                    .Execute Replace:=wdReplaceAll
                End With
            End If
        Next xFooter
    Next xSec
End Sub

【讨论】:

  • 代码执行其任务,但第一页的问题仍然存在
猜你喜欢
  • 2015-03-19
  • 2013-01-30
  • 2018-04-05
  • 1970-01-01
  • 1970-01-01
  • 2019-01-07
  • 2022-01-17
  • 1970-01-01
  • 2017-06-04
相关资源
最近更新 更多