Number of Pages: A Better Way?

G

Gordon Bentley-Mix

Word 2003
Windows Vista Business

I'm trying to determine programmatically the number of pages in one document
for use in another document. I've worked out that:

NumberOfPagesInOtherDoc = OtherDoc.ActiveWindow.Panes(1).Pages.Count

gets me what I want, and it is probably robust enough for my current needs.
However, I'm wondering if there isn't a more efficient way.

I recognise that the concept of "the number of pages in a document" is a
somewhat fluid thing - influenced by stuff like the printer driver, etc. -
but I somehow expected there to be a more direct method for finding this
information. It appears that the Pages collection (and the related Count
property) can only be accessed through the Pane object. This seems a bit...
clunky. Any other suggestions?
 
D

Doug Robbins - Word MVP

NumberofPages = [DocumentObject].BuiltInDocumentProperties(wdPropertyPages)

NumberofPages = [DocumentObject].Range.Information(wdActiveEndPageNumber)

and there may be more.

--
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, originally posted via msnews.microsoft.com
 
G

Gordon Bentley-Mix

Thanks Doug! I knew I could count on you to come up with something more
elegant than tapping into the Panes collection. ;-P

I reckon I'll probably use the first one, since it's something I'm at least
a bit familiar with.

I suppose that will return a String. I need to do some arithmetical
operations with NumberOfPagesInOtherDoc (and I've declared it as Integer in
order to do so), so probably best if I convert the value to the proper data
type along the way. But first I think I'll have some lunch...
--
Cheers!

Gordon Bentley-Mix
Also originally posted via msnews.microsoft.com

Doug Robbins - Word MVP said:
NumberofPages =
[DocumentObject].BuiltInDocumentProperties(wdPropertyPages)

NumberofPages = [DocumentObject].Range.Information(wdActiveEndPageNumber)

and there may be more.

--
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, originally posted via msnews.microsoft.com
 

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