InsertPageNumber Method

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.  

Returns a TextRange object that represents a page number field in a publication.

expression.InsertPageNumber(Type)

expression   Required. An expression that returns one of the objects in the Applies To list.

PbPageNumberType

PbPageNumberType can be one of these PbPageNumberType constants.
pbPageNumberCurrentdefault
pbPageNumberNextInStory Inserts the page number of the next linked text box.
pbPageNumberPreviousInStory Inserts the page number of the previous linked text box.

Example

This example inserts a page number field in a shape on the master page so that the current page number appears at the top of each page.

  Sub PageNumberShape()
    With ActiveDocument.MasterPages(1).Shapes _
            .AddShape(Type:=msoShape5pointStar, Left:=36, _
            Top:=36, Width:=50, Height:=50)
        With .TextFrame.TextRange
            .InsertPageNumber
            .ParagraphFormat.Alignment = pbParagraphAlignmentCenter
        End With
        .Fill.ForeColor.RGB = RGB(Red:=125, Green:=125, Blue:=255)
    End With
End Sub