Two series of page numbers in the same document

G

George-the-cat

Hi. Is there a way to have two sets of page numbers in the same document?
We need one running page number that is the page numbering for the entire
document, and one that is the page numbering for each section. For example,
if I'm in Section 4, I need to show that it's page 95 of the entire document
but only page 6 of Section 4.
Thank you.

We're using Word 2007 and Excel 2007.
 
P

Pesach Shelnitz

Hi,

Pages numbers in the complete document are generated by a PAGE field. Page
numbers within a section are generated by a SECTIONPAGES field, which gives
the current page number within the current section.
 
G

George-the-cat

hmmm. Thank you but it didn't answer the question. I don't want to include
the Section number. So on the bottom left I'll have the overall document page
number 1, 2, 3... 250, and on the right I'll have the section page number
shown just as 1, 2, 3... 50.
Also, all of the sections are different files.
I guess I need an additional/second "Start at" option. Is that possible?
George.
 
P

Pesach Shelnitz

Hi,

The SECTIONPAGES field does what you want. Insert a SECTIONPAGES field where
you want the page within the current section to appear, and you will see the
page number that you want. You can also insert a PAGE field to show the
overall document page number.

Pesach
 
P

Peter Jamieson

Unfortunately although there are { SECTION } and { SECTIONPAGES }
fields, the first just inserts the section number and the second inserts
the total number of pages in the section - there is no field that's the
equivalent of { PAGE } within a section.

Although It looks as if it ought to be feasible to calculate the "page
within section" number using fields in the header, I've never been able
to make it work - at some point, Word seems "unsure" about which section
it is dealing with and behaves rather oddly. Perhaps someone else can
manage it.

So IMO you have to use a macro to do it, and run it prior to printing.
The following scheme seems to work:

In your header, use the nested field

{ ={ PAGE }-{ DOCVARIABLE "SOFAR{ SECTION }" } }

(or if you prefer to reduce space

{={PAGE}-{DOCVARIABLE "SOFAR{SECTION}"}}

)

Each pair of {} needs to be the special Field code braces that you can
insert using ctrl-F9

Use the following macro to repopulate the Document Variables required by
the DOCVARIABLE field.

Sub UpdateSectionPageTotals()
Const strTotalSoFar As String = "SOFAR"
Dim objSection As Word.Section
Dim objVariable As Word.Variable
For Each objVariable In ActiveDocument.Variables
If Left(objVariable.Name, Len(strTotalSoFar)) = strTotalSoFar Then
objVariable.Delete
End If
Next
ActiveDocument.Variables.Add strTotalSoFar & "1", 0
For Each objSection In ActiveDocument.Sections
ActiveDocument.Variables.Add "SOFAR" & CStr(objSection.Index + 1),
objSection.Range.Information(wdActiveEndPageNumber)
' Debug.Print CStr(objSection.Index) + 1,
'objSection.Range.Information(wdActiveEndPageNumber)
Next
End Sub

Peter Jamieson

http://tips.pjmsn.me.uk
 
P

Pesach Shelnitz

Hi,

Peter is correct. I managed to confuse myself with my own faulty testing. I
apologize for the confusion.

There is, however, a much simpler way to achieve the desired page numbering
without the need for a macro.
1) Create a bookmark at the very beginning of each section. For this
example, let's call them StartSec1, StartSec2, etc.
2) Create the following field codes and text in the header for Section 2.
Page {={PAGE} - {PAGEREF StartSec2} + 1} of {SECTIONPAGES} pages in
Section {SECTION}
To do this create the PAGE, PAGEREF, SECTIONPAGES, and SECTION fields in
the
usual way. Then select ={PAGE} - {PAGEREF StartSec2} + 1 and press CTRL+F9.
3) Create similar field codes and text with the appropriate bookmark in the
other sections.
After you see how this works, you can modify the headers as you please.
 
P

Peter Jamieson

FWIW the main reason I make a suggestion based on a macro is because
a. creating one bookmark at the beginning of one section may well be
simple, as the section count goes up and/or if the section structure is
subject to frequent change, then everyone has to adjust the bookmarks
every time a section is inserted/deleted, and that's tedious and
error-prone, at which case my personal view is that it's no longer simple.
b. because of that, many users/organisations are probably going to
resort to a macro to create those bookmarks
c. once you've done that, you may as well accept that running a macro
is part of the publication process

Once you've decided that /a macro/ is needed, it doesn't really matter
how you achieve the overall result, as long as it's easy to use and
reliable. DOCVARIABLEs are little more than a personal preference.
(Nor do I make any claims for the reliability of my approach :)). Or
you could use your approach and have a macro to insert the bookmarks,
and as you say you can also do it without VBA if you want.

Things may get a little trickier anyway, e.g.
d. if you have continuous section breaks I think things are reasonably
straightforward, but maybe not
e. if your section structure does not correspond exactly with Word's
section structure, e.g. you had to have a Word section break to change
landscape/portrait, but you want both types of page to be numbered
within the same section. In that case with a VBA-bsed approach you'd
probably have to tailor the VBA in some way. At that point, relying on
fields that do not reference { SECTIONPAGES ] is probably going to help.

If the document is actally built from separate .doc/.docx files as the
OP has intimated, then I don't think either of our suggestions is going
to work without modification.

Incidentally, the type of "field-only" approach I have tried in the past
but which
f. doesn't work
g. can cause havoc because Word seems to end up continuously updating
header/footer fields

uses fields in the header/footer along the lines of

{SET T1 0}
{SET "T{={SECTION}+1}" {={SECTIONPAGES}+{REF "T{={SECTION}"}}}}
{={PAGE}-{REF "T{SECTION}"}}

so that if section 1 has 3 pages, section 2 has 4 pages etc. then in
theory you would get
T1=0
T2=3
T3=7

i.e. the total number of pages up to the beginning of each section.
Although this doesn't actually appear to have any recursive element in
the calculations, Word seems to re-evaluate the Tn values in some way
that causes them to grow very fast and then stop. In other words, it
pushes Word's field evalution code harder than it wants to go. But
perhaps there is some other way to do those calculations that will work.

Just my 2-c worth :)

Peter Jamieson

http://tips.pjmsn.me.uk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top