|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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. |
#2
|
|||
|
|||
|
#3
|
|||
|
|||
Quote:
|
#4
|
|||
|
|||
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 |
#5
|
|||
|
|||
Another option is to use the VBA Script that Greg provided. Here it is below.
Here is Greg's description for its utility: Quote:
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 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. |
#6
|
||||
|
||||
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 |
#7
|
|||
|
|||
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. |
#8
|
||||
|
||||
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 |
#9
|
|||
|
|||
Quote:
It returns '4', which is correct. (Page D37 is the bookmark for the last page of section one, which is page 4.) Quote:
When used together as you show above it gives syntax error. |
#10
|
||||
|
||||
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 |
#11
|
|||
|
|||
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. |
#12
|
|||
|
|||
Quote:
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? |
#13
|
|||
|
|||
Quote:
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:
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. |
#14
|
|||
|
|||
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 |
#15
|
|||
|
|||
Quote:
Change it to oRng.Collapse wdCollapseStart |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
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 |