| | Help by Product Find help quickly and easily. How-to Resources 2007 Release Learning Resources Support and Feedback Technical Resources | Warning: You are viewing this page with an unsupported Web browser. This Web site works best with Microsoft Internet Explorer 6.0 or later, Firefox 1.5, or Netscape Navigator 8.0 or later. Learn more about supported browsers.
If you perform a task repeatedly in Microsoft Word, you can automate the task by using a macro. A macro is a series of Word commands and instructions that you group together as a single command to accomplish a task automatically. Here are some typical uses for macros:
- 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 (Visual Basic Editor: An environment in which you write new and edit existing Visual Basic for Applications code and procedures. The Visual Basic Editor contains a complete debugging toolset for finding syntax, run-time, and logic problems in your code.). Recording 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 (Visual Basic for Applications (VBA): A macro-language version of Microsoft Visual Basic that is used to program Microsoft Windows–based applications and is included with several Microsoft programs.) 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.
Tips 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.
Creating 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 (object: A table, chart, graphic, equation, or other form of information. Objects created in one application, for example spreadsheets, and linked or embedded in another application are OLE objects.) and properties (property: A named attribute of a control, a field, or an object that you set to define one of the object's characteristics (such as size, color, or screen location) or an aspect of its behavior (such as whether the object is hidden).).
Assigning macros to toolbar buttons, menus, and shortcut keys
For quick access to your macro, you can assign it to a toolbar (toolbar: A bar with buttons and options that you use to carry out commands. To display a toolbar, press ALT and then SHIFT+F10.), a menu, or shortcut keys (shortcut key: A function key or key combination, such as F5 or CTRL+A, that you use to carry out a menu command. In contrast, an access key is a key combination, such as ALT+F, that moves the focus to a menu, command, or control.). 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.
|