Class PageNumber (Word VBA)

The class PageNumber 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.

The main procedures of class PageNumber are Copy, Delete, Select and PageNumbers.Add


To use a PageNumber class variable it first needs to be instantiated, for example

Dim pnr as PageNumber
Set pnr = Selection.HeaderFooter.PageNumbers(Index:=1)

The following procedures can be used to set variables of type PageNumber: PageNumbers.Add, PageNumbers.Item and HeaderFooter.PageNumbers

For Each

Here is an example of processing the PageNumber items in a collection.

Dim pnr As PageNumber
For Each pnr In Selection.HeaderFooter.PageNumbers
Next pnr


These are the main methods of the PageNumber class

Copy - Copies the specified page number to the Clipboard.


Delete - Deletes the specified page number.


Select - Selects the specified page number.


PageNumbers.Add - Returns a PageNumber object that represents page numbers added to a header or footer in a section.

Dim pnr As PageNumber
Set pnr = Selection.HeaderFooter.PageNumbers.Add()


Alignment returns or sets a WdPageNumberAlignment constant that represents the alignment for the page number.

Selection.HeaderFooter.PageNumbers(1).Alignment = wdAlignPageNumberCenter

Index returns a Long that represents the position of an item in a collection.

Dim lngIndex As Long
lngIndex = Selection.HeaderFooter.PageNumbers(1).Index

Parent returns an object that represents the parent object of the specified PageNumber object.

Dim objParent As Object
Set objParent = Selection.HeaderFooter.PageNumbers(1).Parent

PageNumbers.ChapterPageSeparator returns or sets the separator character used between the chapter number and the page number.

Selection.HeaderFooter.PageNumbers.ChapterPageSeparator = wdSeparatorColon

PageNumbers.Count returns a Long that represents the number of page numbers in the collection.

Dim lngCount As Long
lngCount = Selection.HeaderFooter.PageNumbers.Count

PageNumbers.DoubleQuote true if Microsoft Word encloses the specified PageNumbers object in double quotation marks (").

Selection.HeaderFooter.PageNumbers.DoubleQuote = True

PageNumbers.HeadingLevelForChapter returns or sets the heading level style that's applied to the chapter titles in the document.

Selection.HeaderFooter.PageNumbers.HeadingLevelForChapter =

PageNumbers.IncludeChapterNumber true if a chapter number is included with page numbers or a caption label.

Selection.HeaderFooter.PageNumbers.IncludeChapterNumber = True

PageNumbers.NumberStyle returns or sets a WdPageNumberStyle constant that represents the number style.

Selection.HeaderFooter.PageNumbers.NumberStyle = wdPageNumberStyleArabic

PageNumbers.Parent returns an object that represents the parent object of the specified PageNumbers object.

Dim objParent As Object
Set objParent = Selection.HeaderFooter.PageNumbers.Parent

PageNumbers.RestartNumberingAtSection true if page numbering starts at 1 again at the beginning of the specified section.

Selection.HeaderFooter.PageNumbers.RestartNumberingAtSection = True

PageNumbers.ShowFirstPageNumber true if the page number appears on the first page in the section.

Selection.HeaderFooter.PageNumbers.ShowFirstPageNumber = True

PageNumbers.StartingNumber returns or sets the starting note number, line number, or page number.

Selection.HeaderFooter.PageNumbers.StartingNumber =