【发布时间】: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/…