Resting Anchor

The Anchorage

Personal website of Gregory K. Maxey, Commander USN (Retired)

Page Numbering
(A Microsoft Word Help & Tip page by Gregory K. Maxey)

DISCLAIMER/TERMS OF USE

The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.

If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!

Click to donate British Pound Sterling                   Click to donate US dollars                   Click to donate EU euros

This Microsoft Word Tips & Microsoft Word Help page provides some helpful links to page numbering reference material plus some tips of my own.

 The Word MVP FAQ site has several helpful articles on page numbering:  Numbering FAQs

Dual Page Numbering

Sometimes people ask: How to display both "Page X of Y Pages" and "Page X of Z Pages" in the header/footer of a document?

Site Note IconNote:  I use the term "content section" to differentiate and define a document section formed with section breaks consisting of like content (e.g., Marketing, Sales, etc.) from sections formed with section breaks for the purpose of document layout (e.g., page orientation, etc.)

For this demonstration I have used an eight page document containing three sections. Section 1 contains two pages, section 2 contains three pages and section 3 contains three pages. The illustration below depicts dual numbering in section 1:

page numbering 1
page numbering 2
page numbering 3
page numbering 4
page numbering 5

page numbering 6
page numbering 7
The page value in the right hand construction is reset to 1 by subtracting the page number of the previous page form the page number of the current page.

page numbering 8
Here the page number of the last page in section 2 pages is subtracted.

page numbering 9
Dual numbering in "content" section 2.

page numbering 9 B
Dual numbering in "content" section 3.

page numbering 9 C
Resulting numbering in table of contents.

You can use the following VBA procedure to quickly add the necessary bookmarks and nested fields codes needed for section numbering in a document.  The code allows you to add the section page numbering centered in either the headers or footers of your document.  From there you can easily cut and paste them to better suit your requirements.

VBA Script:
Sub InsertSectionPageNumbering()
'Developed by Greg Maxey and Doug Robbins.
Dim lngIndex As Long, lngHF As Long
Dim oRng As Range
Dim oFld As Field, oFldQ As Field
Dim strPlacement As String
Dim bUserSetting As Boolean
  Select Case UCase(InputBox("Enter ""F"" to place section numbering in footers." _
         & "Enter ""H"" to place section numbering in headers.", "Placement", "F"))
    Case "H"
      strPlacement = "Headers"
    Case "F"
      strPlacement = "Footers"
    Case Else
      Exit Sub
  End Select
  With ActiveDocument
    For lngIndex = 1 To .Sections.Count
      .Bookmarks.Add "S" & lngIndex, .Sections(lngIndex).Range.Characters.Last
    Next lngIndex
    bUserSetting = ActiveWindow.View.ShowFieldCodes
    ActiveWindow.View.ShowFieldCodes = True
    FirstSectionSetup .Sections(1), strPlacement
    For lngIndex = 2 To .Sections.Count
      AllOtherSectionSetup .Sections(lngIndex), lngIndex, strPlacement
    Next lngIndex
   .Fields.Update
    ActiveWindow.View.ShowFieldCodes = bUserSetting
  End With
End Sub

Sub FirstSectionSetup(ByRef oSect As Section, Optional strPlacement As String = "Footers")
Dim lngIndex As Long, lngHF As Long
Dim oRng As Range
Dim oFld As Field, oFldQ As Field
Dim oHDs As HeadersFooters

  With oSect
    If strPlacement = "Footers" Then
      Set oHDs = .Footers
    Else
      Set oHDs = .Headers
    End If
    For lngHF = 1 To oHDs.Count
      With oHDs(lngHF)
        Set oRng = .Range
        For Each oFld In oRng.Fields
          If InStr(oFld.Code, " QUOTE") > 0 Then
            oFld.Delete
            Exit For
          End If
        Next
        Set oFldQ = ActiveDocument.Fields.Add(oRng, wdFieldQuote, _
                    PreserveFormatting:=False)
        Set oRng = oFldQ.Code '.Characters.Last.Previous '.Previous '.Previous
        oRng.Collapse wdCollapseEnd
        oRng.Text = """Page "
        oRng.Collapse wdCollapseEnd
        ActiveDocument.Fields.Add oRng, wdFieldPage, PreserveFormatting:=False
        Set oRng = oFldQ.Code.Characters.Last '.Previous
        oRng.Collapse wdCollapseEnd
        oRng.Text = " of "
        Set oRng = oFldQ.Code.Characters.Last
        oRng.Collapse wdCollapseEnd
        ActiveDocument.Fields.Add oRng, wdFieldSectionPages, PreserveFormatting:=False
        Set oRng = oFldQ.Code.Characters.Last
        oRng.Collapse wdCollapseEnd
        oRng.Text = " Section Pages"""
        .Range.Paragraphs(1).Alignment = wdAlignParagraphCenter
      End With
    Next lngHF
  End With
End Sub

Sub AllOtherSectionSetup(ByRef oSect As Section, ByRef lngIndex As Long, _
                         Optional strPlacement As String = "Footers")
Dim lngHF As Long
Dim oRng As Range
Dim oFld As Field, oFldQ As Field
Dim oHDs As HeadersFooters
  With oSect
    If strPlacement = "Footers" Then
      Set oHDs = .Footers
    Else
      Set oHDs = .Headers
    End If
    For lngHF = 1 To oHDs.Count '.Footers.Count
      With oHDs(lngHF) '.Footers(lngHF)
        Set oRng = .Range
        .LinkToPrevious = False
        For Each oFld In oRng.Fields
          If InStr(oFld.Code, " QUOTE") > 0 Then
            oFld.Delete
            Exit For
          End If
        Next
        Set oRng = .Range
        oRng.Collapse wdCollapseStart
        Set oFldQ = ActiveDocument.Fields.Add(oRng, wdFieldQuote, _
                    PreserveFormatting:=False)
        Set oRng = oFldQ.Code
        oRng.Collapse wdCollapseEnd
        oRng.Text = """Page "
        oRng.Collapse wdCollapseEnd
        Set oFld = ActiveDocument.Fields.Add(oRng, wdFieldEmpty, "= ", _
                   PreserveFormatting:=False)
        Set oRng = oFld.Code.Characters.Last.Previous
        ActiveDocument.Fields.Add oRng, wdFieldPage, PreserveFormatting:=False
        Set oRng = oFld.Code.Characters.Last
        oRng.Collapse wdCollapseEnd
        oRng.Text = "- "
        Set oRng = oFld.Code.Characters.Last
        ActiveDocument.Fields.Add oRng, wdFieldEmpty, _
                 Text:="PAGEREF S" & lngIndex - 1, PreserveFormatting:=False
        Set oRng = oFldQ.Code.Characters.Last '.Previous
        oRng.Collapse wdCollapseEnd
        oRng.Text = " of "
        Set oRng = oFldQ.Code.Characters.Last
        oRng.Collapse wdCollapseEnd
        ActiveDocument.Fields.Add oRng, wdFieldSectionPages, PreserveFormatting:=False
        Set oRng = oFldQ.Code.Characters.Last
        oRng.Collapse wdCollapseEnd
        oRng.Text = " Section Pages"""
        .Range.Paragraphs(1).Alignment = wdAlignParagraphCenter
      End With
    Next lngHF
  End With
End Sub

Dual Page Numbering (with a twist)

What if the document contains one or more single "content" sections that requires two or more sections to facilitate page layout or formatting?  There's a twist!

Page numbering 9 D

In this situation, using the method described earlier, your page numbering is this section is all "twisted" up!

Page numbering 9 E
The first page is correct.

Page numbering 9 F
But page 2 and subsequent pages will are not!!

Again, to resolve this issue you can deduce the and display the correct number of "content" section pages using bookmarks, PageRef fields a forumla field.

Page numbering 9 G
Deducing "content" section pages.

Page numbering 9 H

Site Note IconNote:  Special thanks to friend and Word MVP Doug Robbins for his feedback, and suggestions for improving the dual numbering methods outlined above.

Conditional Numbering

I have a cover page on my document that I don't want numbered (or "How do I start numbering with Page 1 on the second or other subsequent page of my document?)

page numbering 10
Field construction

page numbering 11
Document page 1 (front or cover page)

page numbering 12
Document page 2 (first content page)

Site Note IconNote: Using the conditional IF method works for simple page numbering. It will introduce errors if you attempt to use a Table of Contents in your document.

Number Every Other Page Consecutively

If you want to print on the front and back of your paper but only number the front side with a consecutive number, use a "different odd and even" header/footer layout and put the following field construction in the odd page headers:

page numbering 13

Numbering each page as Odd or Even

If you want to to number each page in odd or even increments you can use:

page numbering 14

page numbering 15

That's it! I hope you have found this tips page useful and informative.

Share

DISCLAIMER/TERMS OF USE

The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.

If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!

Click to donate British Pound Sterling                   Click to donate US dollars                   Click to donate EU euros

Search my site or the web using Google Search Engine

Google Search Logo