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

Number of Pages

Status
Not open for further replies.

Zig999

Programmer
Nov 8, 2005
20
BR
Hi,

I need to get the number of pages of a documents list.
I'm trying to use this two properties:

ActiveDocument.BuiltInDocumentProperties("Number of pages")
ActiveDocument.Content.Information(wdActiveEndAdjustedPageNumber)

The problem is that in a loop, with large filesize documents, it is not showing the correct number of pages. I think the problem is that during the loop, Word is not totally loading the document and show the current number of pages (incomplete in this case).

Any ideas of how could I get this?
 
The code is something like this:

Code:
Sub Compare()
    Dim pathName As String, fileName As String
    pathName = "C:\convert\*.*"
    fileName = Dir$(pathName, 0)
    
    ChangeFileOpenDirectory "C:\convert\"
    Do While fileName <> ""
        
        
    Documents.Open fileName:=fileName, ConfirmConversions:=False, _
        ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
        PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
        WritePasswordTemplate:="", Format:=wdOpenFormatAuto
        
        
        MsgBox ActiveDocument.BuiltInDocumentProperties("Number of pages")
        MsgBox ActiveDocument.ComputeStatistics(wdStatisticPages)
        
        ActiveDocument.Close
        fileName = Dir$()
    Loop
    
End Sub

For example, a document with 51 pages show me it has only 3 pages. A document with 5 pages but with a lot of images (large filesize) show me only 2 pages.
 
You are likely correct. Word does not know the number of pages in a document. Word derives page layout via the printer driver. If the file is opened by Word using another printer driver, the pagination may be different, therefore the page numbers could be different. Page numbers is not a value that is stored in the file. It must repaginate the document when it opens it.

I think the instruction to get the page number is actioned before Word has a chance to fully repaginate. Put a wait instruction in.

Gerry
 
Thanks for the answer Gerry.
I´ll try that...

Zig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top