Microsoft Office Forums How to add a running tally of "page # per # of pages in chapter" in lower right corner of footer

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-04-2019, 03:04 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: 110
Swarup is on a distinguished road
Default How to add a running tally of "page # per # of pages in chapter" in lower right corner of footer

In my document I have the page number in the middle of the footer. This page number is of course a running count that goes from the beginning to the end of the book. I would like to add in the right corner of the footer a running tally of the page number per number of pages in the chapter.

So for example if page number 59 of the book is the 3rd page of chapter 4, and if chapter 4 has ten pages in it, then there will be a "59" in the middle of the footer to reflect that overall page number, and in the right corner of the footer it will say "3 of 10" to show that this is the third page of ten pages in the chapter.



I am ready to add this notation by hand for the entire document; the problem I am facing is that in my document, each chapter is a section. Even if one has set the headers to be different for even pages vs odd pages, still, MS Word makes the footer the same for all the even numbered pages of a section (as it does for odd pages). So it is not permitting me to make page 2 of the chapter have "2 of 4" in the right corner, whereas page 4 of the same chapter to have "4 of 4". Short of making each and every page a separate section, is there any way to create this running tally in the right corner of the footer?

Last edited by Swarup; 08-04-2019 at 06:19 PM.
Reply With Quote
  #2  
Old 08-05-2019, 10:21 AM
Charles Kenyon Charles Kenyon 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
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 5,941
Charles Kenyon is a name known to allCharles Kenyon is a name known to allCharles Kenyon is a name known to allCharles Kenyon is a name known to allCharles Kenyon is a name known to allCharles Kenyon is a name known to all
Default

Page Numbering by Greg Maxey, MVP
Page Numbers in Word 2007-2019 (365)
Reply With Quote
  #3  
Old 08-05-2019, 03:26 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: 110
Swarup is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
I see, yes-- both of you have done a nice job explaining this concept and the approach to make it work. Thank you for the helpful links. I will try and see if I can manage it. Will report back here and let you know how it goes.
Reply With Quote
  #4  
Old 08-05-2019, 09:14 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: 110
Swarup is on a distinguished road
Default

Using the example given in Greg Maxey's site, I was able to set up the "X of Z" for the first chapter using the simple approach "{ page } of { SectionPages }". It worked beautifully! And Greg explained that this simple approach cannot be used for the subsequent chapters, as in the "X of Z" for chapters after the first, we will again want X to be starting from 1. (Whereas in the regular page number field we need it to be of an ongoing nature from one section to the next.)

To solve this, Greg guides to create a bookmark at the end of every chapter (i.e. end of every section), and then to use this following model to get the X of Z to restart at the beginning of every section with an X of 1--

{={ Page }-{ PageRef mybookmark } }

So in chapter two, I tried taking the page field, highlighting and toggling it, then changing its contents to the above (where I substituted 'mybookmark' with D37 which is the bookmark I had created). When I again toggled the field code to get the result, it gave the message "syntax error". Any suggestion what is the syntax error I made?

The field code is currently:

{PAGE \* Arabic \* MERGEFORMAT }

In place of that I put:

{={ Page }-{ PageRef D37} }

When I again toggled the field code to get the result, it gives me "syntax error".

I also tried the below, as the when I toggle the field code, for the page number this is what actually appears: { PAGE \* Arabic \* MERGEFORMAT}. So I kept all of that, and tried simply adding the rest of the code given in Greg's site to minus the PageRef of the page before the given section begins.

{={ PAGE \* Arabic \* MERGEFORMAT}-{ PageRef D37} }

But when I again toggled the field code to get the result, it again gives me "syntax error".

I also tried capitalizing the word "page", as MS word had it capitalized:

{={ PAGE }-{ PageRef D37} }

But it still gives me "syntax error".

Last edited by Swarup; 08-06-2019 at 06:38 AM. Reason: Added the code for further attempts to get it right
Reply With Quote
  #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: 110
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
  #6  
Old 08-06-2019, 03:16 PM
Guessed's Avatar
Guessed Guessed 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
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,260
Guessed has a spectacular aura aboutGuessed has a spectacular aura aboutGuessed has a spectacular aura about
Default

Surely you can run the macro to see the answer to question 1.

Is it ready to go? Again, run the macro and see what it does. If you have to ask the first question it is apparent that you have neither read nor executed the code.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 08-06-2019, 03:27 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: 110
Swarup is on a distinguished road
Default

I haven't read the code true, as I am not at all familiar with these things. That code is like Swahili language to me. Moreover, I have been working on this book for several years, and I am frankly a bit scared to execute something which is going to have purview/effect over the entire file. Especially when I am not sure even whether it will be in the header or the footer, and what it is going to do to my existing page numbers which I worked quite hard to get the way I wanted.


If you could have a look at the post I posted just previous to the VBA script, I would far prefer to solve that syntax error and implement the code myself, chapter by chapter. In that way I will be able to understand what is going on.
Reply With Quote
  #8  
Old 08-06-2019, 05:13 PM
Guessed's Avatar
Guessed Guessed 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
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,260
Guessed has a spectacular aura aboutGuessed has a spectacular aura aboutGuessed has a spectacular aura about
Default

Forget the macro if you don't have the confidence to run it.

To debug your flawed nested fields, try each field on their own
What does { Page } return?
What does { PageRef D37} return?

If both these return what you would expect, try putting them both inside to give
{={ Page }-{ PageRef D37} }
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #9  
Old 08-06-2019, 09:54 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: 110
Swarup is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
Forget the macro if you don't have the confidence to run it.

To debug your flawed nested fields, try each field on their own
What does { Page } return?
It returns '6', which is correct. (This is page 6, and the 2nd page of the 2nd section.)

Quote:
Originally Posted by Guessed View Post
What does { PageRef D37} return?
It returns '4', which is correct. (Page D37 is the bookmark for the last page of section one, which is page 4.)

Quote:
Originally Posted by Guessed View Post
If both these return what you would expect, try putting them both inside to give
{={ Page }-{ PageRef D37} }
When used individually, they each give correct returns.
When used together as you show above it gives syntax error.
Reply With Quote
  #10  
Old 08-06-2019, 11:10 PM
Guessed's Avatar
Guessed Guessed 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
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,260
Guessed has a spectacular aura aboutGuessed has a spectacular aura aboutGuessed has a spectacular aura about
Default

It works fine on my machine. Perhaps you need to post a sample document.

I assume you have copied the successful fields inside the parent field
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #11  
Old 08-06-2019, 11:17 PM
Charles Kenyon Charles Kenyon 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
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 5,941
Charles Kenyon is a name known to allCharles Kenyon is a name known to allCharles Kenyon is a name known to allCharles Kenyon is a name known to allCharles Kenyon is a name known to allCharles Kenyon is a name known to all
Default

Then you have the containing calculation field wrong. I have used these methods and they work.


Alternative 1:

Use a copy of your document and use the macro on it. See what happens. It won't hurt.
Install/Employ VBA Procedures (Macros) by Greg Maxey, MVP


Alternative 2:

Otherwise, contact Greg directly and ask him what his fees are. I have used code that he has written for years with good results.
Reply With Quote
  #12  
Old 08-07-2019, 04:15 AM
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: 110
Swarup is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
It works fine on my machine. Perhaps you need to post a sample document.

I assume you have copied the successful fields inside the parent field

I did not copy the successful fields, no. I typed them out to make the parent field. The reason being, that I tried pasting into these fields in the past few days working with this, and found that any time I do a paste into a field, it pastes over the entire field-- obliterating anything else that was there in the field. Seeing this failure of copy-paste to paste into the field, I had to leave behind the notion of copy-paste in this setting. I was putting my cursor in the exact place in the field where I wanted to copy-paste, and still I was finding that this happened. So I abandoned copy-paste.


1. Am I doing something wrong in my attempts with copy-paste?


2. This parent field/calculated field is not a lengthy thing to type out. It should work perfectly well even if I type it out, shouldn't it?
Reply With Quote
  #13  
Old 08-07-2019, 04:19 AM
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: 110
Swarup is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
Then you have the containing calculation field wrong. I have used these methods and they work.

True. There must be some sort of simple error I am making. But I sure it is typed out correctly. Unless one just cannot type these things out, what I am doing should work. Now, one question here is that I notice the {} marks at the very beginning and end of the field are in bold, whereas the {} which I type when I put the two fields into the calculated field, are not in bold. Could this be a problem?


Quote:
Originally Posted by Charles Kenyon View Post
Alternative 1:

Use a copy of your document and use the macro on it. See what happens. It won't hurt.
Install/Employ VBA Procedures (Macros) by Greg Maxey, MVP

Excellent idea. I will try this on a copy of the document and see what happens. I would nonetheless very much like to get to the bottom of what is going wrong when I try to type those fields out myself.
Reply With Quote
  #14  
Old 08-07-2019, 09:04 AM
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: 110
Swarup is on a distinguished road
Default

I created a copy of my file, and used the instructions in the link you provided for creating and running a macro. The macro got created properly, with no errors. When I then ran it, it gave me the following notice: "compile error: syntax error". And it is highlighting the following line, which it has put in red:

Code:
oRng Collapse wdCollapseStart
Reply With Quote
  #15  
Old 08-07-2019, 09:29 AM
Charles Kenyon Charles Kenyon 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
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 5,941
Charles Kenyon is a name known to allCharles Kenyon is a name known to allCharles Kenyon is a name known to allCharles Kenyon is a name known to allCharles Kenyon is a name known to allCharles Kenyon is a name known to all
Default

Quote:
Originally Posted by Swarup View Post
I created a copy of my file, and used the instructions in the link you provided for creating and running a macro. The macro got created properly, with no errors. When I then ran it, it gave me the following notice: "compile error: syntax error". And it is highlighting the following line, which it has put in red:

Code:
oRng Collapse wdCollapseStart

Change it to
oRng.Collapse wdCollapseStart
Reply With Quote
Reply

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
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


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


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