Running Your Recorded Macro

After you have recorded a macro, you can run the macro. Running the macro causes Excel to carry out all the actions recorded in the macro.

To run a macro in Excel, use the Macros button that appears on the Developer ribbon (and also on the View ribbon). Clicking the Macros button causes Excel to display the Macro dialog shown in Figure 1.6.

Select the macro you want to run in the Macro Name list, and then click the Run button to execute that macro. (Other buttons in the Macro dialog are described in following chapters.)

For example, to run the FormatArialRedBold12 Excel macro you just recorded, follow these steps:

  1. Select a cell in a worksheet (preferably one that contains some text, so you can see the changes).

  2. Click the Macro button on the Developer ribbon to display the Macro dialog.

  3. Select the PERSONAL.XLSB!FormatArialRedBold12 macro in the Macro Name list.

  4. Click the Run button to execute the FormatArialRedBold12 macro. The text in whatever cell was selected when you ran the FormatArialRedBold12 macro has its formatting changed to 12-point bold Arial font in a red color.

  5. The Macro dialog in Excel lists the macros stored in any workbooks that are currently open, including workbooks that are open but hidden (refer to Fig. 1.6). The name of the workbook that contains the macro is listed in front of the macro name in the Macro Name list if the macro is not in the current workbook (as with the PERSONAL.XLSB!FormatArialRedBold12 macro). If the macro you want isn't listed, you must open the workbook in which the macro is stored to make the macro available before you open the Macro dialog.

If you assigned a shortcut key in Excel's Record Macro dialog, you can run that specific macro by pressing the assigned shortcut-key combination. As with the macros listed in Excel's Macro dialog, only macros stored in a currently open workbook (it doesn't have to be the active workbook) have their shortcut keys activated.

For example, when recording the FormatArialRedBold12 macro you set the shortcut key for the macro as Ctrl+Shift+F. Select another cell containing unformatted text, and press Ctrl+Shift+F – Excel will run the FormatArialRedBold12 macro the same as if you had used the Macro dialog.

As you might already know, you can also run a macro by assigning it to a button or graphic object placed directly into an Excel worksheet. You can also run macros in Excel by creating a custom ribbon. Chapter 26 "Creating Custom Dialogs with User Forms" explains how to attach a macro to a button or image placed directly on a worksheet, and Chapter 27, "Creating Custom Ribbons for Your Workbooks," explains how to create customized ribbons to run your macros.