Microsoft Office Tutorials and References
In Depth Information
Getting Acquainted with Workbook-Level Events
Ans = MsgBox(Msg, vbYesNo, “About to print...”)
If Ans = vbNo Then Cancel = True
End Sub
The Workbook_BeforePrint procedure is executed before the workbook is printed. This
routine displays the message box shown in Figure 19-4. If the user clicks the No button, Cancel is
set to True , and nothing is printed.
Figure 19-4: You can cancel the print operation by changing the Cancel argument.
The BeforePrint event also occurs when the user previews a worksheet.
Unfortunately, Excel doesn’t provide a sheet-level BeforePrint event. Therefore, your code
can’t determine which sheet is about to be printed. Often, you can assume that the
ActiveSheet is the sheet that will be printed. However, there is no way to detect if the user
requests that the entire workbook be printed.
Getting Acquainted with Workbook-Level Events
Workbook -level events occur within a particular workbook. Table 19-1 lists the commonly used
workbook events, along with a brief description of each. Consult the Help system for a complete
list of Workbook -level events. Workbook event-handler procedures are stored in the code
module for the ThisWorkbook object.
Table 19-1: Commonly Used Workbook Events
Event
Action That Triggers the Event
Activate
A workbook is activated.
AddinInstall
A workbook is installed as an add-in.
AddinUninstall
A workbook is uninstalled as an add-in.
After Save
A workbook has been saved.
BeforeClose
A workbook is about to be closed.
BeforePrint
A workbook (or anything in it) is about to be printed or previewed.
BeforeSave
A workbook is about to be saved.
 
Search JabSto ::




Custom Search