none
Using the numpages pages field in VBA RRS feed

  • Question

  • Hi

    What are the VBA objects/collection that control and can manipulate the numpages and pages fields. Also if I want to create a simple user form or code that allows the user depending on the number of different sections in a document control the starting number for each section.

    Any help on this would be greatly appreciated.

    Thanks

    Monday, January 7, 2013 10:56 PM

Answers

  • ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).PageNumbers.RestartNumberingAtSection = True
    ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).PageNumbers.StartingNumber = 4

    You would need to elaborate more on what you are after with a userform.  Or maybe the following macro would do what you want:

    Dim i As Long
    With ActiveDocument
        For i = 2 To .Sections.Count
            If MsgBox("Do you want the numbering in this Section to continue from that in the previous Section", vbQuestion + vbYesNo) = vbYes Then
                .Sections(i).Headers(wdHeaderFooterPrimary).PageNumbers.RestartNumberingAtSection = True
            Else
                .Sections(i).Headers(wdHeaderFooterPrimary).PageNumbers.RestartNumberingAtSection = False
                .Sections(i).Headers(wdHeaderFooterPrimary).PageNumbers.StartingNumber = InputBox("Enter the starting number.", , 1)
            End If
        Next i
    End With


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org

    • Marked as answer by tfitzhardinge Tuesday, January 8, 2013 6:11 AM
    Tuesday, January 8, 2013 5:39 AM

All replies

  • ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).PageNumbers.RestartNumberingAtSection = True
    ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).PageNumbers.StartingNumber = 4

    You would need to elaborate more on what you are after with a userform.  Or maybe the following macro would do what you want:

    Dim i As Long
    With ActiveDocument
        For i = 2 To .Sections.Count
            If MsgBox("Do you want the numbering in this Section to continue from that in the previous Section", vbQuestion + vbYesNo) = vbYes Then
                .Sections(i).Headers(wdHeaderFooterPrimary).PageNumbers.RestartNumberingAtSection = True
            Else
                .Sections(i).Headers(wdHeaderFooterPrimary).PageNumbers.RestartNumberingAtSection = False
                .Sections(i).Headers(wdHeaderFooterPrimary).PageNumbers.StartingNumber = InputBox("Enter the starting number.", , 1)
            End If
        Next i
    End With


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org

    • Marked as answer by tfitzhardinge Tuesday, January 8, 2013 6:11 AM
    Tuesday, January 8, 2013 5:39 AM
  • Doug

    That is perfect thank you.

    Tuesday, January 8, 2013 6:10 AM