Microsoft Office Online
Sign in to My Office Online (What's this?) | Sign in

 
 
Help and How-to
Search
Search
 
Check for updates: (c) Microsoft
Microsoft Update
 
 
 
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.

Email this linkEmail this link Printer-Friendly VersionPrinter-Friendly Version Bookmark and ShareShare
About macros
 

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.).

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 (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.

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.

ShowAssigning 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 (menu: A list of commands that is displayed when you click a menu name on a menu bar or other toolbar.), 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.

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 (script anchor: The visual representation of a script on a Web page that you open in a Microsoft Office program. Script anchors are not displayed by default. Different script anchors represent scripts written in different scripting languages.) and Microsoft Script Editor (Microsoft Script Editor: Used to add text, edit HTML tags, and edit any Microsoft Visual Basic Scripting Edition (VBScript) code in a data access page. You can also view your page in the Script Editor as it would appear in a Web browser.).

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.

advertisement