Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Page Count

Status
Not open for further replies.

jsolutions

Programmer
Jul 18, 2002
157
US
This is a follow up to thread707-1001749 which asked how to isolate part of a header or footer. With much help and many headaches, I was able to isolate what I needed from the footer. However, now I still need to be able to find the number of pages in a section - or worst case scenario find the total number of pages in the entire document.

I've gone through the PageNumbers collection and tried using the count funtion. It seems to always return Zero though.

Any direction on this would be much appreciated.
 
Actually, just found how to get the total number of pages -
Code:
ActiveWindow.Selection.Information(wdNumberOfPagesInDocument)
Quite intuitive, right?

As a follow up, does anyone know if there is a way to find the total number of pages for a section??
 
Hi jsolutions,

You can use
Code:
[blue]activedocument.sections(1).range.ComputeStatistics(wdStatisticPages)[/blue]
but the range includes the section break at the end of the section and therefore usually gives a value greater than the actual number of pages.

A possible way to overcome this is to use
Code:
[blue]activedocument.range(activedocument.sections(3).range.start, activedocument.sections(3).range.End-1).ComputeStatistics(wdStatisticPages)[/blue]
In this case you may find that the last section of the document (which isn't terminated by a section break) occasionally (when the end of the document just falls on a new page thus giving a blank page at the end) understates the number of pages by one - you can probably live with this as easily as you can the odd behaviour which causes it.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top