How do I programmatically calculate the current page or total pages?
Thanks
The number of the current page (if you define that as the page where
the insertion point is, regardless of whether it's on screen at the
moment) is either
Selection.Information(wdActiveEndPageNumber)
or
Selection.Information(wdActiveEndAdjustedPageNumber)
These give the same number unless the section containing the selection
has a page-number restart. In that case, the first one gives the total
count of pages from the beginning of the document, while the second
one gives the number that a {Page} field would display.
The total number of pages is similar:
ActiveDocument.Range.Information(wdActiveEndPageNumber)
In Word 2003 there is finally (!) a Pages collection, so you can ask
for
ActiveDocument.ActiveWindow.ActivePane.Pages.Count
which should give you the same number. To use this, the document has
to be in Print Layout view.