View Single Post
 
Old 11-26-2025, 01:39 PM
macropod's Avatar
macropod macropod is online now Windows 10 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,521
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You're going about this in a very convoluted way. There is no need to loop through all Sections or to activate the Header/Footer pane.
For example:
Code:
Sub InsertFooterPage()
Application.ScreenUpdating = False
Dim HdFt As HeaderFooter, Rng As Range
For Each HdFt In ActiveDocument.Sections.Last.Footers
  If HdFt.Exists Then
    Set Rng = ActiveDocument.Fields.Add(Range:=HdFt.Range, Type:=wdFieldIf, Text:="{} = {} {}", PreserveFormatting:=False).Code
    With Rng
      .Collapse wdCollapseStart
      .MoveStartUntil "{"
      .End = .End + 2
      .Text = ""
      .Fields.Add Range:=Rng, Type:=wdFieldPage, PreserveFormatting:=False
      .Collapse wdCollapseEnd
      .MoveStartUntil "{"
      .End = .End + 2
      .Text = ""
      .Fields.Add Range:=Rng, Type:=wdFieldNumPages, PreserveFormatting:=False
      .Collapse wdCollapseEnd
      .MoveStartUntil "{"
      .End = .End + 2
      .Text = ""
      .Fields.Add Range:=Rng, Type:=wdFieldAutoText, Text:="MyBuildingBlock3", PreserveFormatting:=False
    End With
  End If
Next
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote