Microsoft KB Archive/246693: Difference between revisions
m (Text replacement - "&" to "&") |
m (Text replacement - """ to """) |
||
Line 59: | Line 59: | ||
Create a new program, enter the code below, and then run the program.<br /> | Create a new program, enter the code below, and then run the program.<br /> | ||
<pre class="codesample">IF | <pre class="codesample">IF "3.00"$VERSION() ; | ||
OR | OR "5.00"$VERSION() | ||
SET LIBRARY TO HOME()+'foxtools.fll' | SET LIBRARY TO HOME()+'foxtools.fll' | ||
ENDIF | ENDIF | ||
CLEAR | CLEAR | ||
oWord = CREATEOBJECT( | oWord = CREATEOBJECT("Word.Application") | ||
WITH oWord | WITH oWord | ||
IF | IF "3.00"$VERSION() ; | ||
OR | OR "5.00"$VERSION() ; | ||
OR | OR "8167"$VERSION() | ||
cur_dir=SYS(5)+SYS(2003) && Get the current folder | cur_dir=SYS(5)+SYS(2003) && Get the current folder | ||
ELSE | ELSE | ||
Line 78: | Line 78: | ||
CD (word_dir) | CD (word_dir) | ||
word_doc = GETFILE('doc') && Insert Word doc here if known | word_doc = GETFILE('doc') && Insert Word doc here if known | ||
WAIT WINDOW | WAIT WINDOW "Please wait while I obtain document statistics..." NOWAIT | ||
.Documents.OPEN(word_doc) | .Documents.OPEN(word_doc) | ||
num_pages = .ActiveDocument.ComputeStatistics(2) && 2=number of pages | num_pages = .ActiveDocument.ComputeStatistics(2) && 2=number of pages | ||
Line 84: | Line 84: | ||
ENDWITH | ENDWITH | ||
=MESSAGEBOX( | =MESSAGEBOX("Number of pages in "+PROPER(JUSTSTEM(ALLTRIM(word_doc))) + ; | ||
": " +ALLTRIM(STR(num_pages))) | |||
IF | IF "3.00"$VERSION() ; | ||
OR | OR "5.00"$VERSION() | ||
SET LIBRARY TO | SET LIBRARY TO | ||
SET DEFA TO (cur_dir) && Switch back to the original folder | SET DEFA TO (cur_dir) && Switch back to the original folder |
Latest revision as of 13:50, 21 July 2020
Article ID: 246693
Article Last Modified on 7/1/2004
APPLIES TO
- Microsoft Visual FoxPro 3.0 Standard Edition
- Microsoft Visual FoxPro 3.0b Standard Edition
- Microsoft Visual FoxPro 5.0 Standard Edition
- Microsoft Visual FoxPro 5.0a
- Microsoft Visual FoxPro 6.0 Professional Edition
This article was previously published under Q246693
SUMMARY
Often times it is useful to obtain document statistics from Word 97 or Word 2000 using OLE Automation, especially when printing documents. This article illustrates how to retrieve the number of pages in a given Word document.
MORE INFORMATION
Using the ComputeStatistics method in Microsoft Word, you can obtain several statistics about a Word document, such as the number of pages, the number of words and the number of characters. This article demonstrates how to obtain the number of pages in a given Word document. For more information on the ComputeStatistics method, see the Word VBA online help.
Create a new program, enter the code below, and then run the program.
IF "3.00"$VERSION() ; OR "5.00"$VERSION() SET LIBRARY TO HOME()+'foxtools.fll' ENDIF CLEAR oWord = CREATEOBJECT("Word.Application") WITH oWord IF "3.00"$VERSION() ; OR "5.00"$VERSION() ; OR "8167"$VERSION() cur_dir=SYS(5)+SYS(2003) && Get the current folder ELSE cur_dir = .Options.DEFAULTFILEPATH(14) && Get the current folder ENDIF word_dir = .Options.DEFAULTFILEPATH(0) && Look in user's document folder VFP 6.0 SP3. CD (word_dir) word_doc = GETFILE('doc') && Insert Word doc here if known WAIT WINDOW "Please wait while I obtain document statistics..." NOWAIT .Documents.OPEN(word_doc) num_pages = .ActiveDocument.ComputeStatistics(2) && 2=number of pages .APPLICATION.QUIT(0) ENDWITH =MESSAGEBOX("Number of pages in "+PROPER(JUSTSTEM(ALLTRIM(word_doc))) + ; ": " +ALLTRIM(STR(num_pages))) IF "3.00"$VERSION() ; OR "5.00"$VERSION() SET LIBRARY TO SET DEFA TO (cur_dir) && Switch back to the original folder ELSE CD (cur_dir) && Switch back to the original folder ENDIF
REFERENCES
(c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Dean Christopher, Microsoft Corporation.
Keywords: kbhowto KB246693