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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to count the number of pages in a doc 2

Status
Not open for further replies.

nesplb

Programmer
Jul 29, 2003
109
NO
Does anyone know how I can count the number of pages in a word document?
Maybe a too simple question but....:$
In advance thanX!:)

Pål Nesteby

PDC-Tangen
Norway
 
HI nesplb
This should work for you.

Code:
activedocument.BuiltInDocumentProperties("number of pages").value

HTH

Matt
[rockband]
 
Try this:
ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thank you very much!
Exactly what I needed!:D

Pål Nesteby

PDC-Tangen
Norway
 
But.....
-Sometimes the code says only 1 page even if I've got 299, and and sometimes it say 4 pages etc. Does anybody know why this happen?

in advance thanx!

Pål Nesteby

PDC-Tangen
Norway
 
You may consider forcing word repagination:
Application.ScreenUpdating = False
ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview
Application.ScreenUpdating = True
Debug.Print ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Sorry....I'm still getting the "wrong answer".
But if I wait for a minute or so, it shows the right number of pages....

Pål Nesteby

PDC-Tangen
Norway
 
Perhaps a SaveAs will update the page count ?
Or a Selection.EndKey Unit:=wdStory ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
This is very strange....
I've tried all of your tips but nothing seems to help except from just waiting....hmmm
I could have been waiting if this wasn't an autprocess that is supposed to start and end without any human-touch...



Pål Nesteby

PDC-Tangen
Norway
 
And what about this ?
ActiveDocument.Content.Information(wdNumberOfPagesInDocument)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
YESSSSSSSSS!!:D
That's the one! heheh
Thank you very much!
A purple star for you!:)

Pål Nesteby

PDC-Tangen
Norway
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top