Thread: [Solved] Word page numbering
View Single Post
 
Old 05-17-2025, 11:52 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Frankly I wouldn't bother with inserting a building block by macro, or rely on the recorder, but to achieve the same result with a macro, try the following:
Code:
Sub InsertPageNumInHeader()
Dim oRng As Range
    Set oRng = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
    With oRng
        .ParagraphFormat.Alignment = wdAlignParagraphCenter
        .Text = "[]"
        .Collapse 1
        oRng.Start = oRng.Start + 1
        .Fields.Add oRng, wdFieldPage, "", False
    End With
    Set oRng = Nothing
End Sub
And yes, the online help is correct about the macro recorder. See Installing Macros
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote