Running Macros When a Workbook Is Opened
One advantage of writing Excel 2007 macros in VBA is that you can have Excel 2007 run a macro whenever a workbook is opened. For example, if you use a worksheet for presentations, you can create macros that render the contents of selected cells in bold type, italic, or different typefaces to set the data apart from data in neighboring cells. If you close a workbook without removing that formatting, however, the contents of your workbook will have highlights when you open it. Although this is not a catastrophe, returning the workbook to its original formatting might take a few seconds to accomplish.
Instead of running a macro by hand, or even from a toolbar button or a menu, you can have Excel 2007 run a macro whenever a workbook is opened. The trick of making that happen is in the name you give the macro. Whenever Excel 2007 finds a macro with the name Auto_Open, it runs the macro when the workbook to which it is attached is opened.
If you have your macro security set to the Disable with Notification level, clicking the Options button that appears on the Message Bar, selecting the Enable this Content option button, and then clicking OK allows the Auto_Open macro to run.
In this exercise, you will create a macro to run whenever someone opens the workbook to which it is attached.
USE the RunOnOpen workbook in the practice file folder for this topic. This practice file is located in the My Documents\Microsoft Press\Excel SBS\Macros folder.
OPEN the RunOnOpen workbook.
CLOSE the RunOnOpen workbook.