Consulting

Results 1 to 4 of 4

Thread: Restart page numbering at section 1 only with VBA

  1. #1
    VBAX Regular
    Joined
    Aug 2016
    Posts
    10
    Location

    Exclamation Restart page numbering at section 1 only with VBA

    I have a document that runs a script to set the intro pages (TOC, List of Figures, etc.) to use lowercase roman numerals. When I get to section 1, I am currently using PageNumbers.RestartNumberingAtSection and PageNumbers.StartingNumber = 1. However, when my script gets to a major section heading (single number vs. 1.2.3), the script uses Selection.InsertBreak Type:=wdSectionBreakNextPage, which is causing them to be new sections and thus restarts numbering back at 1, but I want it to continue numbering from the previous section. So, if Section 1 ends at page 7, I want Section 2 to start at page 8, instead of 1 like it is now. How do I, in VBA, allow succeeding pages simply continue with the numbering from the previous page?

    Chris

  2. #2
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,273
    Location
    How about posting the code? It's impossible to give specific advice without seeing it.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Regular
    Joined
    Aug 2016
    Posts
    10
    Location

    Question

    Sorry 'bout that. Here's the part of the code that I have for setting page numbers:
    With Selection.Find
        .Text = Chr(13) + "<IntentionalBlankCheck"
        .Replacement.Text = ""
        .Wrap = wdFindContinue
    End With
    
    If Selection.Find.Execute = True Then
        Selection.EndKey unit:=wdLine, Extend:=wdExtend
        If Selection.Text = Chr(13) + ""<IntentionalBlankCheck-SectionBreak>" + Chr(13) Then
            'Reset Numbering to not start numbering at section breaks
            ActiveDocument.Sections(currSect).Footers(wdHeaderFooterPrimary).PageNumbers.RestartNumberingAtSection = False
            'Delete the text, add Section break and check if on an even or odd page
            'If on even page, then add "This Page Intentionally Left Blank."
        ElseIf Selection.Text = Chr(13) + ""<IntentionalBlankCheck-Section1>" + Chr(13) Then
            'Delete the text, add Section break and check for even/odd page as above
           
            '**************Code to set Starting number to 1********************
            currSect = Selection.Information(wdActiveEndSectionNumber)
            ActiveDocument.Sections(currSect).Footers(wdHeaderFooterPrimary).PageNumbers.RestartNumberingAtSection = True
            ActiveDocument.Sections(currSect).Footers(wdHeaderFooterPrimary).PageNumbers.StartingNumber = 1
        End If
    As you can see, I have code that sets the Restart Numbering variable to false [I]every[I] time I see anything other than -Section1> just to be safe, but it still keeps starting sections at page 1.

  4. #4
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,273
    Location
    That's still not a meaningful amount of code. For example, there's no context to indicate what currSect is.

    And, since you're apparently trying to do something to a document based on its content via Find/Replace, it would also be helpful if you could attach a document to a post with some representative data (delete anything sensitive). You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •