Editing a Macro


Microsoft Office Specialist Sometimes a macro does not work as you expect, and you need to modify it. You can rerecord the macro to correct the problem, or because macros are instructions written in Microsoft Visual Basic for Applications (VBA), you can edit it in the Visual Basic Editor.

Word macros are stored in modules within a Visual Basic macro project that is stored in a document or template. To edit a macro, you display the Macros dialog box, click the macro, and then click Edit. The Visual Basic Editor program window opens, and you can then select the module you want to work on and make changes.

When you no longer need a macro, you can delete it from the document or template where it is stored by selecting it in the Macros dialog box and clicking Delete.

Tip

If you create a toolbar button or menu command for a macro and then delete the macro from the document or template, you can delete the macro’s button or command by holding down the [ALT] key and dragging it into any blank space in the document window.

In this exercise, you will edit an existing macro to add character formatting, and then you’ll delete the macro.

USE

the ModifyMacro document in the practice file folder for this topic. This practice file is located in the My Documents\Microsoft Press\Word 2003 SBS\IncreasingEfficiency\EditingMacro folder and can also be accessed by clicking Start/All Programs/Microsoft Press/Word 2003 Step by Step.

OPEN

the ModifyMacro document. If Word asks you whether you want to enable macros or disable macros, click Enable Macros.

  1. On the Tools menu, point to Macro, and then click Macros to open the Macros dialog box.

  2. In the list of macros, click Letter, and click Edit.

    The macro’s instructions are displayed in the Visual Basic Editor code window.

  3. Scroll to the bottom of the ModifyMacro - NewMacros (Code) window.

    click to expand

    Troubleshooting

    You might have to move this window by dragging its title bar, or resize it by dragging its lower-right corner.

  4. Click to the left of Selection.TypeText Text:="Karen Berg", and press [ENTER] to insert a blank line before that instruction.

  5. Press the key, and type Selection.Font.Bold=wdToggle.

    As you type, the Visual Basic Editor displays a menu of possible commands. You can select a command from the menu instead of typing the entire command. When you’ve finished, the new instruction appears in the code.

    click to expand

    The new instruction tells the program that the following text should be displayed in bold.

    Important

    For information about inserting and editing macro commands in the Visual Basic Editor or about creating macros that perform complicated tasks that cannot be recorded, use the Help menu in the Visual Basic Editor window.

  6. On the File menu, click Close and Return to Microsoft Word.

    The Visual Basic Editor closes, and the macro is saved with the change.

  7. Close any floating toolbars, and press [CONTROL]+[END] to move to the end of the document.

  8. On the Tools menu, point to Macro, and then click Macros to open the Macros dialog box.

  9. Click the down arrow to the right of the Macros in box, and click ModifyMacro (document).

    Tip

    You don’t have to open the Macros dialog box and select a macro to run it. You can simply press [ALT]+ (lowercase el), the keyboard shortcut assigned to the Letter macro when it was originally created.

  10. In the list of macros, click Letter, and then click Run.

    Troubleshooting

    If Word tells you that the macros in this project are disabled, your Security level is probably set to High. On the Tools menu, point to Macro, and then click Security to open the Security dialog box. On the Security Level tab, click Medium, and then click OK. Now save, close, and reopen the ModifyMacro document, clicking Enable Macros when asked. After completing this exercise on editing a macro, be sure to return your security setting to High if you do not want to have the option to run unsigned macros, which could contain viruses. (Unsigned macros do not have digital signatures that guarantee their source.)

    A set of letter placeholders appears at the end of the document.

  11. On the Tools menu, point to Macro, and then click Macros to open the Macros dialog box.

  12. Make sure the setting in the Macros in box is ModifyMacro (document).

  13. In the list of macros, click Letter, and then click Delete.

    An alert box asks you to confirm that you want to delete the Letter macro.

  14. Click Yes.

    Word deletes the Letter macro.

  15. Close the Macros dialog box.

    Save

  16. On the Standard toolbar, click the Save button to save the document.

    CLOSE

    the ModifyMacro document, and quit Word.




Microsoft Office Word 2003 Step by Step
MicrosoftВ® Office Word 2003 Step by Step (Step by Step (Microsoft))
ISBN: 0735615233
EAN: 2147483647
Year: 2003
Pages: 156

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