PageNumber Object

Microsoft Word Visual Basic

PageNumbersPageNumber

Represents a page number in a header or footer. The PageNumber object is a member of the PageNumbers collection. The PageNumbers collection includes all the page numbers in a single header or footer.

Using the PageNumber Object

Use PageNumbers(index), where index is the index number, to return a single PageNumber object. In most cases, a header or footer will contain only one page number, which is index number 1. The following example centers the first page number in the primary header in section one in the active document.

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
    .PageNumbers(1).Alignment = wdAlignPageNumberCenter
		

Use the Add method to add a page number (a PAGE field) to a header or footer. The following example adds a page number to the primary footer in the first section and in any subsequent sections. The page number doesn't appear on the first page.

With ActiveDocument.Sections(1)
    .Footers(wdHeaderFooterPrimary).PageNumbers.Add _
        PageNumberAlignment:=wdAlignPageNumberLeft, _
        FirstPage:=False
End With