Printing-Related Methods
The PrintOut method will print all or part of a document. Its syntax is:
DocumentObject.
PrintOut(Background, Append, Range, _
OutputFileName, From, To, Item, Copies, Pages, _
PageType, PrintToFile, Collate, FileName, _
ActivePrinterMacGX, ManualDuplexPrint
)
Note that the PrintOut method can also be applied to a Window object to print the contents of the window, or it can be used globally, as in:
PrintOut "d:\word\letter.doc"
to print the active document. The myriad arguments of the method correspond to the items on the Print dialog box. All of these arguments are optional variants.
In addition to using the PrintOut method in this global way, we frequently want to exercise greater control over printing. The following sections examine some of the ways that you can do that.
Printing to a File
To print to a file, set the following parameters of the PrintOut method:
- PrintToFile
Set this to True to print to a file.
- OutputFileName
Set this to the full path and name of the output file.
- Append
Set this to True to append the document to the output file or False to over-write the contents of the output file.
Restricted Printing
To restrict printing, set the following parameters:
- Range
The page range for printing. It can be any one of the constants in the following enum:
Enum WdPrintOutRange wdPrintAllDocument = 0 wdPrintSelection = 1 wdPrintCurrentPage = 2 wdPrintFromTo = 3 wdPrintRangeOfPages = 4 End Enum
- From
If
Range
iswdPrintFromTo
, set this to the starting page number. ...
Get Writing Word Macros, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.