The This Workbook object

Under each node in the Project Explorer labeled Microsoft Excel Objects is a node labeled ThisWorkbook. This node represents the project's workbook, along with the code component (also called a code module) that stores event code for the workbook. (We can also place independent procedures in the code component of a workbook module, but these are generally placed in a standard module, discussed later in this chapter.)

Simply put, the purpose of events is to allow the VBA programmer to write code that will execute whenever one of these events fires. Excel recognizes 19 events related to workbooks. We will discuss these events in Chapter 11; you can take a quick peek at this chapter now if you are curious. Some examples:

• The Open event, which occurs when the workbook is opened.

• The BeforeClose event, which occurs just before the workbook is closed.

• The NewSheet event, which occurs when a new worksheet is added to the workbook.

• The BeforePrint event, which occurs just before the workbook or anything in it is printed.

0 0

Post a comment