4. Running Macros

4.1 Running a Macro

As explained in section 3.1, the macros available to be run are those in the Personal Macro Workbook and in the open workbooks. In this tutorial we will assume that all macros are stored in the Personal Macro Workbbok, but it is possible that existing workbooks you open contain macros as well.

To run a macro click on Tools/Macros/Macro (2003) or View/Macros/View Macros (2007/2010). A dialog box will appear, listing the macros available to be run. You can filter the list of macros displayed by making a selection in the "Macros in" field. The names of macros in open workbooks other than the active workbook are preceded by the name of the containing workbook plus an exclamation point. Once you have selected the macro, click on "Run."

Remember that when you run a macro, it runs on the active worksheet (no matter where the macro is stored), unless specified otherwise by the appropriate macro commands. For the purposes of this tutorial we will assume that the macros will run on the active worksheet.

To repeat an important point made earlier, with certain actions that involve entering settings on a dialog box, such as page setup, when you record a macro all the settings on the dialog box are recorded, not just the one(s) you change. This needs to be kept in mind when recording and running macros. This subject is covered in detail later in this tutorial.

4.2 Always Save Before Running a Macro!

You should always save the workbook before you run a macro! Macros will do exactly what we program them to do (like the demon in The Sorcerer's Apprentice). Unfortunately we sometimes discover after the fact that that was not what we really wanted to do. Do not depend on "undo" because you may not be able to undo the actions the macro has taken. Even if that is possible, you might have to go back many levels to restore the workbook to its original state. Get into the habit of saving the workbook before you run a macro; that way you can recover from any mistake.

4.3 Terminating the Macro

Simple macros run so quickly that they are finished before you have a chance to stop them. For more complex macros that take longer to run, and especially if you have accidentally programmed an endless loop into the macro, you can stop the macro by pressing the Escape key. A VBA message box will open; select "End" to terminate the macro.