I need to open a document in Word and get the number of pages. My documents have only one section. The problem is that if the document has more than two pages, the number of pages returned is 2 (or 1, as the case may be). Any number of pages greater than two returns only two, not the correct number.
I discovered that if I waited a few seconds for the entire document to load, the correct number of pages was returned. I'm using the wait verb to accomplish this, but I'm thinking there must be a better way.
I've tried setting autoyield to .f. and using the doevents verb, but it either doesn't work or I'm doing something wrong with it.
I'm using VFP 7, Word 2000, Windows 2000.
stripped down code example:
go_WordApp = createobject("word.application")
lc_DocFileName = "c:\five_page_document.doc"
Store .F. To GV_ConfirmConversions, GV_ReadOnly, GV_AddToRecentFiles
go_WordApp.Documents.Open(lc_DocFileName, GV_ConfirmConversions, GV_ReadOnly, GV_AddToRecentFiles)
* If I omit the wait stmt the number of pages returned is
* two. Adding the wait stmt allows the
* correct number of pages to be returned, in this case five.
Wait "" Timeout 3
ln_number_of_pages = go_WordApp.ActiveDocument.Sections(1).Range.Information(3)