Page 174 - Microsoft Office Excel 2003 Programming Inside Out
P. 174
Part 3: The Excel Object Model
Microsoft Office Excel 2003 Programming Inside Out
Note You should have an error-handling routine in place to inform the user if the workbook
fails to print. If possible, you should also write a routine to print the workbook on another
printer and, in any case, inform the user on which printer the procedure printed the workbook.
Chapter 7
Table 7-5 lists and describes the parameters available for use with the PrintOut method. The
settings and descriptions are straightforward, with one exception. When you set the Preview
parameter to True, Excel displays the workbook in Print Preview mode, within which the
user must click the Print button to begin printing.
Table 7-5. The Parameters of the PrintOut Method
Parameter Type Description
Expression Required An expression that refers to a workbook, a
worksheet, a chart, an object, or a cell range.
From Optional Variant The number of the page at which to start printing. If
this argument is omitted, printing starts at the
beginning.
To Optional Variant The number of the last page to print. If this argument
is omitted, printing ends with the last page.
Copies Optional Variant The number of copies to print. If this argument is
omitted, one copy is printed.
Preview Optional Variant True to have Excel invoke print preview before
printing the object. False (or omitted) to print the
object immediately.
ActivePrinter Optional Variant Sets the name of the active printer.
PrintToFile Optional Variant True to print to a file. If PrToFileName isn’t specified,
Excel prompts the user to enter the name of the
output file.
Collate Optional Variant True to collate multiple copies.
PrToFileName Optional Variant If PrintToFile is set to True, this argument specifies
the name of the file you want to print to.
If you want to take a user directly to Print Preview, you can do so using the PrintPreview
method. The PrintPreview method, which also applies to sheets, charts, objects, and cell
ranges, has a single parameter: EnableChanges. When the EnableChanges parameter is set to
True (the default), the user is able to change the workbook’s page setup and margin settings
before printing. When EnableChanges is set to False, the Page Setup and Margins buttons are
disabled, but the user can still choose whether to print (by clicking the Print button) or not
(by clicking the Close button).
148