Using Word s Macro Recorder


Using Word's Macro Recorder

The quickest and easiest way to get started using Word's macro feature is to use its macro recorder. The macro recorder records the steps you perform within Word, automatically writing the VBA code that makes up the macro. You can then run the macro to repeat the steps.

There are two potential "gotchas" that you may encounter when using the macro recorder:

  • The macro recorder cannot record mouse movements within the document window. So if you want to select text or reposition the insertion point as part of a macro, you must use shortcut keys to do it.

  • The macro recorder will record every keystroke and menu choice you make. So if you make a mistake, it's recorded as part of the macro, too.

To make the most of the macro recorder and record a macro correctly the first time, you should have a solid understanding of what you want the macro to do and what steps are required to complete the task. Don't be afraid to jot down a few notes before starting the recorder. A little advance preparation may save you time in the long run.

To record a macro

1.

If necessary, open the document you want to have open when recording the macro steps and position the insertion point or select text as desired.

2.

Choose Tools > Macro > Record New Macro (Figure 1) to display the Record Macro dialog (Figure 2).

Figure 1. The Macro submenu under the Tools menu.


Figure 2. The Record Macro dialog.


3.

Enter a name for the macro in the Macro name box. The name cannot contain any spaces or special characters.

4.

Choose a location to store the macro from the Store macro in pop-up menu (Figure 3).

Figure 3. The Store macro in pop-up menu.


5.

If desired, enter a description for the macro by editing the contents of the Description box.

6.

Click OK. The tiny Stop Recording toolbar appears (Figure 4).

Figure 4. The tiny Stop Recording toolbar.


7.

Perform the steps you want to record. (Remember that the macro recorder won't record mouse movements or clicks within the document window.)

8.

When you are finished performing all of the steps you want to include in the macro, click the Stop Recording button on the Stop Recording toolbar. The Stop Recording toolbar disappears and your macro steps are saved.

Tips

  • In step 4, if you want to store the macro in a specific template or document, make sure that template or document is open before you open the Record Macro dialog.

  • After step 5, you can click the Toolbars button or Keyboard button to display the Commands pane of the Customize Toolbars/Menus dialog (Figure 5) or the Customize Keyboard dialog (Figure 6). I explain how to use these dialogs to assign toolbar buttons and shortcut keys to commands, including macros, in Chapter 20. Clicking OK in either of these dialogs starts the macro recorder.

    Figure 5. The Commands tab of the Customize Toolbars/Menus dialog. Use this dialog to assign a macro to a toolbar button.


    Figure 6. The Customize Keyboard dialog. Use this dialog to assign a shortcut key to a macro.


  • In step 3, if you enter the name of an existing macro, when you click OK to begin recording the macro a dialog like the one in Figure 7 will appear. Click Yes to overwrite the macro; click No to return to the Record Macro dialog so you can rename the macro you want to record.

    Figure 7. A dialog like this appears when you attempt to record a macro with the same name as an existing macro.


  • In step 7, you can pause macro recording at any time by clicking the Pause Recording button on the Stop Recording toolbar. The button looks pushed in (Figure 8) or selected until you click it again to resume recording.

    Figure 8. The Stop Recording toolbar with the Pause Recording button selected.



To run a macro

1.

If necessary, open the document you want to have open when running the macro and position the insertion point or select text as desired.

2.

Choose Tools > Macro > Macros to display the Macros dialog.

3.

Select the name of the macro you want to run (Figure 9).

Figure 9. The Macros dialog with three macros defined.


4.

Click Run. The macro steps are performed, just the way they were recorded (but a heck of a lot quicker).

Tip

  • If this is the first time you're running a macro that modifies the contents of a document, you might want to save the document before running the macro. This way you can revert to the saved copy if something goes wrong during macro execution.


To delete a macro

1.

Choose Tools > Macro > Macros to display the Macros dialog.

2.

Select the name of the macro you want to delete (Figure 9).

3.

Click Delete.

4.

A confirmation dialog like the one in Figure 10 appears. Click Yes.

Figure 10. This dialog confirms that you really do want to delete a macro.




MIcrosoft Word 2004 for Mac OSX. Visual QuickStart Guide
MIcrosoft Word 2004 for Mac OSX. Visual QuickStart Guide
ISBN: N/A
EAN: N/A
Year: 2003
Pages: 199

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net