Microsoft Office Tutorials and References
In Depth Information
On the new menu, right-click the menu item you just renamed and click Assign
Macro. Then, in the Assign Macro dialog box, click the name of the macro you want to
assign to the menu item and click OK.
Debugging a Macro
Part of the art of writing and recording macros is debugging , or the process of discovering
why your VBA code isn’t working the way it should. The Visual Basic Editor provides quite a
few tools for you to use in testing a macro you’ve recorded or written. One interesting tech€
nique you can use to debug your code is to step through the code one instruction at a time.
To start the process, click Tools, Macro, Macros, <macro_name> , Step Into to display
the macro in the Visual Basic Editor.
From within the editor, press F8 to execute the next macro instruction. As shown in
Figure 3-4, an arrow will appear beside the next instruction to be executed, and the
instruction itself will be highlighted.
Figure 3-9. The Visual Basic Editor shows you which line of code will be
Subsequent presses of F8 will execute the highlighted step in the macro and highlight the next
step, if any. There are a number of other ways you can control how your macro executes.
Table 3-1 lists those keyboard shortcuts and offers a brief description of what each shortcut