Page X of Y where Y does not equal Numpages nor SectionPages

S

Sally Green

Hi

I'm using Word 2003 and have a template for a large document. At template
stage there is a cover page (actual page 1), a second cover page (actual page
2), a TOC (actual page 3) all in Section 1. No page numbering is required on
these pages. Currently the actual fourth page is the start of Section 2 and
page numbering commences at Page 1 on this page. Depending on the length of
the finished document the TOC could run over into a second, third or even
fourth page. In that scenario the first page of section 1 (numbered as 1)
might possibly be the 5th, 6th, or even 7th actual page in the document.

So if I end up with 14 pages in the document with only 3 pages in section 1
my last page should read Page 11 of 11 (Scenario 1). Or if I had 2 TOC
pages, so therefore had 4 pages in section 1, my last page should read Page
10 of 10 (Scenario 2).

So assuming Scenario 1:
With using Page of Numpages I would get Page 11 of 14
With using Page of SectionPages I might get Page 11 of 11 providing they
don't insert a section break mid-way (some of these documents can get to over
a hundred pages) with appendices in landscape so a section break would be
required.
I can't set a bookmark on the last page in the template so that I can use
Page of PageRef BookmarkName as I can't rely on that bookmark staying there
for the duration of the document creation. I've created a module to go to
the end of the document, create the bookmark, so that I can then use PageRef.
However, they could only run this after the doucment has been created and
they may edit it afterwards and not run the module again. I really would
like a field that can automatically update without having to rely on human
error.

I can create a bookmark after the TOC that will move down with the TOC to
give me the overall number of pages in section 1. Can I create a formula to
subtract this number from NumPages. ie:
Page {Page} of ({NumPages}-{PageRef bmLastPageNoInTOC})
This example only returns:
PAGE 11 OF (14-3)

Any suggestions would be greatly appreciated.
 
S

Sally Green

This code returns the correct page number of the last numbered page but I
don't know how to get it into the footer of the template. I tried to create
a Function (instead of a Sub) as I would in Excel but didn't have any success
with that.

Sub Pages()
Dim lngLastPageNoInTOC, lngTotalNoOfPages As Long
ActiveDocument.Bookmarks("bmLastPageNoInTOC").Select
lngLastPageNoInTOC = Selection.Information(wdActiveEndPageNumber)

lngTotalNoOfPages = Selection.Information(wdNumberOfPagesInDocument)

lngTotalNoOfPages = lngTotalNoOfPages - lngLastPageNoInTOC
End Sub

Cheers
Sally
 
S

Sally Green

Solution, thanks to Suzanne from an earlier posted question, gave me the idea
of putting my formula inside another field bracket set. So the solution is
(I'm typing the brackets here but you'll get the general idea):

Page {PAGE} of {={NUMPAGES}-{PAGEREF bmLastPageNoInTOC}}

My bookmark is called bmLastPageNoInTOC and is positioned directly after the
TOC on Page 3 in the template. As the TOC is updated and may go to several
pages the bookmark will always appear after the TOC, so PAGEREF will pick up
the actual page number of the last page in the TOC.

Many thanks. A good trick to learn.

Sally
 
D

Doug Robbins - Word MVP

Or you could use a DOCVARIABLE field in the footer and set the value of the
variable using your code.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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