• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 12. Automating Repetitive Tasks ... > Running a Macro When a Workbook Is O...

Running a Macro When a Workbook Is Opened

One advantage of writing Excel macros in VBA is that you can have Excel 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, italics, or different typefaces to set the data apart from data in neighboring cells. If you should close a workbook without removing that formatting, however, the contents of your workbook will have highlights when you open it. While this is not a catastrophe, returning the workbook to its original formatting will take only a few seconds to accomplish.


Rather than run a macro by hand, or even from a toolbar button or a menu, you can have Excel run a macro whenever a workbook is opened. The trick to making that happen is in the name you give the macro. Whenever Excel finds a macro with a name starting with Auto_ (Auto followed by an underscore), it runs the macro when the workbook to which it is attached is opened.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint