About macros

Microsoft Office Word 2003

  • To speed up routine editing and formatting
  • To combine multiple commands; for example, inserting a table with a specific size and borders, and with a specific number of rows and columns
  • To make an option in a dialog box more accessible
  • To automate a complex series of tasks
  • Word offers two ways to create a macro: the macro recorder and the Visual Basic Editor.

    ShowRecording a macro

    The macro recorder in Word acts like a tape recorder. It records your deliberate keystrokes and mouse button clicks by translating them into Microsoft Visual Basic for Applications code. When you record a macro, you can use the mouse to click commands and options, but not to select text. You must use the keyboard to record these actions. For example, you can use F8 to select text and press END to move the cursor to the end of the line.

    ShowTips for recording macros

    • Before you record a macro, plan the steps and commands you want the macro to perform.
    • If you make a mistake when you record the macro, corrections you make will also be recorded. You can edit the macro later to remove unnecessary steps you recorded.
    • Try to anticipate any messages that Word might display that can prevent your macro from running.
    • If the macro includes the Edit menu Find or Replace commands, click More on the Find or Replace tabs, and then click All in the Search box. If the macro searches up or down only, Word stops the macro when it reaches the beginning or end of the document and displays a message asking whether you want to continue searching.
    • If you want to use the macro you're recording in other documents, make sure that the macro doesn't depend on the current document's contents.
    • If you use a particular macro often, assign it to a toolbar button, a menu, or shortcut keys. That way, you can run the macro directly without having to open the Macros dialog box.

    ShowCreating macros by using the Microsoft Visual Basic Editor

    You can use the Visual Basic Editor to create very flexible, powerful macros that include Visual Basic instructions that you cannot record.

    When you use the Visual Basic Editor, you can get additional assistance, such as reference information about objects and properties.

    ShowAssigning macros to toolbar buttons, menus, and shortcut keys

    For quick access to your macro, you can assign it to a toolbar, a menu, or shortcut keys. Running the macro is as simple as clicking the toolbar button or menu command or pressing the shortcut keys.

    If you give a newly created macro the same name as an existing built-in command in Word, the new macro actions will replace the actions of the built-in command. For example, if you record a new macro and name it FileClose, it becomes attached to the Close command. When you choose the Close command, Word performs the new actions you recorded.

    Note  If you do this by mistake, simply delete the newly created macro, and re-record it under a new name. The built-in command retains the original actions.

    ShowStoring macros

    You can store macros in templates or in documents. By default, Word stores macros in the Normal template so that they're available for use with every Word document. If you plan to use a macro in a single document, store it in that document. Individual macros in a document are stored in macro projects that you can copy from one document to another.

    ShowAutomating tasks in Web pages

    To automate a task in a Word document that you save and publish as a Web page, instead of using a macro, you use a script anchor and Microsoft Script Editor.

    Script anchors mark where you want to store a script in your Word document. When you double-click the script anchor in the Word document, Microsoft Script Editor starts so that you can program or edit the script. The script runs when the Web page is displayed in the Web browser.