Page 64 - Excel Progamming Weekend Crash Course
P. 64
d540629 ch03.qxd 9/2/03 9:27 AM Page 39
Session 3 — The Excel Object Model 39
add-ins; then use the ThisWorkbook keyword to ensure that a reference applies to the
workbook the code is in and not to the active workbook.
The ThisWorkbook keyword is not the same as the ThisWorkbook element
that is listed in the Project Explorer.
Note
Printing Workbooks
You use the PrintOut method to print all or part of a workbook. The syntax for this method is:
WB.PrintOut(From, To, Copies, Preview, ActivePrinter, PrintToFile,
Collate, PrToFileName)
All of the arguments to this method are optional:
From, To. The first and last pages of the workbook to print. The default is to print
the entire workbook.
Copies. The number of copies to print. The default is 1.
Preview. If set to True, the Excel Print Preview window opens for the user to view.
The default is False.
ActivePrinter. The name of the printer to use. The default is the Windows default
printer.
PrintToFile. If True, the output is sent to a disk file rather than to the printer.
The default is False.
Collate. If True and multiple copies are being printed, the output is collated. The
default is False.
PrToFileName. The name of the file for output (relevant only when PrintToFile
is True).
The PrintOut method is available with several other Excel objects, including
Chart, Range, Window, and Worksheet.
Tip
E-Mailing a Workbook
The Workbook object’s SendMail method enables you to e-mail a workbook to one or more
recipients. The workbook is sent as an attachment to an e-mail message using whatever
e-mail system is installed on the system. The syntax is:
WB.SendMail(Recipients, Subject, ReturnReceipt)
Here’s what each of these arguments do:
Recipients. A required argument listing one or more recipients for the message
(see the text for details).