|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
可试试如下代码,其基本效果为删除页眉页脚中带有页码或页数域的句子内容。
Sub test()
Dim aSection As Section, i As Byte, aHeaderFooter As HeaderFooter, aField As Field
Application.ScreenUpdating = False
For Each aSection In ActiveDocument.Sections
For i = 1 To 2
For Each aHeaderFooter In IIf(i = 1, aSection.Headers, aSection.Footers)
If aHeaderFooter.Range.Fields.Count > 0 Then
For Each aField In aHeaderFooter.Range.Fields
If aField.Type = wdFieldPage Or wdFieldNumPages Or wdFieldSectionPages Then
aField.Select
Selection.Expand wdSentence
Selection.Delete
End If
Next
End If
Next
Next i
Next
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.Panes(2).Close
ActiveWindow.View.Type = wdPrintView
End If
Application.ScreenUpdating = True
End Sub |
|