Running Your Macro

Now that you have recorded and stored your macro, you can run the macro to perform the steps you have recorded. Use one of the following methods to run your macro:

  • If you assigned the macro to a toolbar button, you can click the button to run the macro.

  • If you assigned the macro to a menu command, you can select the command to run the macro.

  • If you assigned a keyboard shortcut for the macro, press the key combination.

  • To select the macro name from the list of available macros, choose Tools, Macro, Macros, or press Alt+F8. The Macros dialog box appears, as shown in Figure 32.5. Select the macro name that you want to run and click Run to execute the macro.

    Figure 32.5. Use the Macros dialog box to select a macro to run.



When you first display the Macros dialog box, Word lists all the macros currently available for you to run. The list can include macros in your template, macros in the active template or document, and macros in other global templates that are open.

To shorten the list to include only those macros in one template or document, select the template or document in the Macros In drop-down list. To restore the full list of macros, select All Active Templates and Documents in the drop-down list.

Dealing with Macro Error Messages

When your macro runs, the statements you recorded are performed just as you recorded them. Sometimes, though, an error can occur. Suppose that you recorded a macro that tries to open a file name that no longer exists on your hard drive. If the macro can't find the file, it will cause an error, and display a message such as the one shown in Figure 32.6.

Figure 32.6. When a Microsoft Visual Basic error occurs, you can end the macro or debug it using the Visual Basic Editor.


If you're not interested in debugging the macro, click End. The macro stops running, and you are returned to the active document in Word. Examine your document carefully because some of the statements in your macro might have executed successfully, up until the point where the error occurred.

If you want to examine the VBA code in the Visual Basic Editor (VBE), click Debug in the error dialog box. The VBE is opened, and the line of VBA code in which the error occurred is highlighted, as shown in Figure 32.7.

Figure 32.7. The line of code that caused the error is highlighted.


At this time, the macro is still running but is suspended in a state known as Break mode. Before you can resume normal operations, you must reset the macro project by clicking the Reset button on the VBE's Standard toolbar, or by choosing Run, Reset from the VBE menus.


Occasionally, a macro runs out of control, repeating its actions over and over. This is not likely to happen with a recorded macro, but it sometimes happens when there is a programming error in a macro you have edited. In this case, you can stop the macro by pressing Ctrl+Break. Again, this puts the macro in Break mode, and you must reset the macro project.

Opening Additional Templates to Run Macros

If you want to run a macro that is stored in a different template, you can open that template as a global template. There are two ways to make sure that a template is loaded globally:

  • Save the template in the Word Startup folder. This folder is listed in the Startup item in the Tools, Options, File Locations dialog box. Any template in this folder is opened invisibly, and as a read-only document, each time you start Word.

  • Open a template globally at any time with the Tools, Templates and Add-Ins command. Click the Add or Remove buttons to load and unload templates from memory, as displayed in the Global Templates and Add-Ins list.

Clicking Add displays the Add Templates dialog box; browse to and select the template you want to load. After a template is loaded as a global template, its macros, toolbars, and keyboard shortcuts are available, along with those in any other templates and documents that are open.

    Part I: Word Basics: Get Productive Fast
    Part II: Building Slicker Documents Faster
    Part III: The Visual Word: Making Documents Look Great
    Part IV: Industrial-Strength Document Production Techniques
    Part VI: The Corporate Word