Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 08-06-2019, 02:23 PM
Swarup Swarup is offline How to add a running tally of "page # per # of pages in chapter" in lower right corner of footer Windows 10 How to add a running tally of "page # per # of pages in chapter" in lower right corner of footer Office 2016
Competent Performer
How to add a running tally of "page # per # of pages in chapter" in lower right corner of footer
 
Join Date: Jul 2018
Posts: 188
Swarup is on a distinguished road
Default

Another option is to use the VBA Script that Greg provided. Here it is below.

Here is Greg's description for its utility:

Quote:
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.
Code:
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
The questions I have for this are:
1. Greg says above that this script will place the needed X of Z format in the middle of the header or footer. Which is the script going to put it in-- the header or the footer?

I already have page numbering for this 300 page document set up in the middle of the footer, as well as in the outside corner of the header. Is this script going to disturb that arrangement? I had put a lot of work into setting that up the way I wanted it.

2. Is this VBA script ready to go? And is it going to bring about what I had described in my first post on this thread, i.e. an X of Z (section pages) that I can then cut and paste into the right lower corner of my footer?

I am also ready to set this up myself manually for each chapter. Just need a bit of guidance to solve the syntax error described in the previous post.
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add a running tally of "page # per # of pages in chapter" in lower right corner of footer How do I lower the position of the page number in the footer? lgambis Word 9 02-24-2018 10:38 AM
How to add a running tally of "page # per # of pages in chapter" in lower right corner of footer Bookmark not replaced when inserting but to lower right corner of image newbieX Word VBA 6 11-20-2015 02:03 PM
designating seperate settings (even & odd pages, first page omitted) for header and footer? xhgrrr Word 3 04-02-2015 05:58 PM
How to add a running tally of "page # per # of pages in chapter" in lower right corner of footer Advanced page numbering: section pages in header, document pages in footer Albus Word 12 12-12-2014 01:36 PM
print pages with footer of last page different roytom Excel 1 12-13-2010 02:09 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:20 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft