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. 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)

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

Alignment

Returns or sets a WdPageNumberAlignment constant that represents the alignment for the page number. Possible return values are wdAlignPageNumberCenter - Centered, wdAlignPageNumberInside - Left-aligned just inside the footer, wdAlignPageNumberLeft - Left-aligned, wdAlignPageNumberOutside - Right-aligned just outside the footer, wdAlignPageNumberRight - Right-aligned.


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

Copy

Copies the specified page number to the Clipboard.


Selection.HeaderFooter.PageNumbers(1).Copy

Cut

Removes the specified object from the document and places it on the Clipboard.

If expression returns a Range or Selection object, the contents of the object are moved to the Clipboard but the collapsed object remains in the document.


If ActiveDocument.Fields.Count >= 1 Then 
 ActiveDocument.Fields(1).Cut 
 Selection.Collapse Direction:=wdCollapseEnd 
 Selection.Paste 
End If

Delete

Deletes the specified page number.


Selection.HeaderFooter.PageNumbers(1).Delete

Index

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


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

Select

Selects the specified page number.

After using this method, use the Selection property to work with the selected items. For more information, see Working with the Selection Object.


Selection.HeaderFooter.PageNumbers(1).Select