Article ID: 176069 - Last Review: February 24, 2005 - Revision: 3.4 How to print a range of pages in Word by using OLE automationThis article was previously published under Q176069 On This PageSUMMARY
Printing either a range or selection of pages in a Microsoft Word for Windows
document from Microsoft Visual FoxPro for Windows using OLE automation requires
additional parameters for the PrintOut method of Word for Windows 97 or Microsoft Office Word 2003 or the
FilePrint command in Microsoft Word for Windows 95.
All the parameters that are passed to Word in an OLE automation statement are positional. For example, the Range parameter is the third argument out of 15 in the parameter list for the PrintOut method. Therefore, arguments 1 and 2 must have the appropriate value for the argument and cannot be left out. However, any arguments past the last argument with a value do not need to be included in the command. For example, if no other parameters require a value after the Range is set, then Range could be the last argument passed to the PrintOut method. MORE INFORMATION
The code samples in this article are written to run exclusively with a
particular version of Word. The examples for Word for Windows 95 were
written to work with both Visual FoxPro for Windows versions 3.0b, 5.0a,
and 6.0. The Word 97 example works only with Visual FoxPro for Windows
versions 5.0a with Service Pack 2 installed or Visual FoxPro 6.0 and later. If the code is used
with any other version of Word or Visual FoxPro for Windows, the following
OLE error may occur:
OLE error code 0x80020005: Type Mismatch.
0 Prints the entire document 1 Prints the selection 2 Prints the current page 3 Prints the range of pages specified by the From and To parameters 4 Prints the range of pages specified by Pages parameter PrintOut(Background, Append, Range, OutputFileName, From, To, Item, Copies, Pages, PageType, PrintToFile, Collate, FileName, ActivePrinterMacGX, ManualDuplexPrint) FilePrint(.Background, .AppendPrFile, .Range, .PrToFileName, .From, .To, .Type, .NumCopies, .Pages, .Order, .PrintToFile, .Collate, .FileName, .OutputPrinter) Printing contiguous range of pagesThere are two ways to print a contiguous range of pages using the Range parameter. Both methods depend on the value of Range. For instance, if the Range is set to 3, then set the From and To parameters. If the Range is 4, use the Pages parameter. Both methods are discussed below. In each code example, the FilePrint and PrintOut commands are shown using both variables and the explicit values for the arguments. This provides a better representation of the positions these arguments will take in the statement. The command using variables is commented out.Method 1: Range argument set to 3With the Range set to 3, the From and To parameters need to set for both the PrintOut method in Word 97 or Microsoft Office Word 2003 and FilePrint command in Word 95.For example, to print pages 4 through 8 of Testdoc.doc use the following Code. Note This works with Word 95 and Visual FoxPro for Windows versions 3.0, 5.0, and 6.0. Method 2: Range argument set to 4Assign 4 to the Range argument, then assign the pages to be printed to the Pages argument. To print pages 4 through 8, the Pages argument would be "4- 8."Note This works with Word 95 and Visual FoxPro for Windows versions 3.0, 5.0, and 6.0: Printing non-contiguous range of pagesTo print non-contiguous pages, set the Range parameter to 4 and the Pages parameter to the pages to print. For example, to print page 2 and then pages 6 through 9, the Pages argument would be "2,6-9." The Pages parameter is set the same for both Word 95 and Word 97.Note This works in Word 95 and Visual FoxPro for Windows versions 3.0, 5.0, and 6.0: REFERENCES
Microsoft Word Visual Basic Help
APPLIES TO
| Article Translations
|
Back to the top
