What are macros in microsoft word

Word for Microsoft 365 Word for the web Word 2021 Word 2019 Word 2016 Word 2013 Word 2010 Word 2007 More…Less

In Word, you can automate frequently used tasks by creating and running macros. A macro is a series of commands and instructions that you group together as a single command to accomplish a task automatically.

To save time on tasks you do often, bundle the steps into a macro. First, you record the macro. Then you can run the macro by clicking a button on the Quick Access Toolbar or pressing a combination of keys. It depends on how you set it up.

  1. Click View > Macros > Record Macro.

    Record Macro command

  2. Type a name for the macro.

    Macro name box

  3. To use this macro in any new documents you make, be sure the Store macro in box says All Documents (Normal.dotm).

    Box for choosing where to store a macro

  4. To run your macro when you click a button, click Button.

    Click to assign the macro to a button

  5. Click the new macro (it’s named something like Normal.NewMacros.<your macro name>), and click Add.

    The macro and the Add button

  6. Click Modify.

    Modify button in the Customize the Quick Access Toolbar box

  7. Choose a button image, type the name you want, and click OK twice.

    Button options in the Modify Button box

  8. Now it’s time to record the steps. Click the commands or press the keys for each step in the task. Word records your clicks and keystrokes.

    Note: Use the keyboard to select text while you’re recording your macro. Macros don’t record selections made with a mouse.

  9. To stop recording, click View > Macros > Stop Recording.

    Stop Recording command

The button for your macro appears on the Quick Access Toolbar.

Macro button on the Quick Access Toolbar

To run the macro, click the button.

  1. Click View > Macros > Record Macro.

    Record Macro command

  2. Type a name for the macro.

    Macro name box

  3. To use this macro in any new documents you make, be sure the Store macro in box says All Documents (Normal.dotm).

    Box for choosing where to store a macro

  4. To run your macro when you press a keyboard shortcut, click Keyboard.

    Click to assign the macro to a keyboard shortcut

  5. Type a combination of keys in the Press new shortcut key box.

  6. Check to see whether that combination’s already assigned to something else. If it’s already assigned, try a different combination.

  7. To use this keyboard shortcut in any new documents you make, be sure the Save changes in box says Normal.dotm.

  8. Click Assign.

  9. Now it’s time to record the steps. Click the commands or press the keys for each step in the task. Word records your clicks and keystrokes.

    Note: Use the keyboard to select text while you’re recording your macro. Macros don’t record selections made with a mouse.

  10. To stop recording, click View > Macros > Stop Recording.

    Stop Recording command

To run the macro, press the keyboard shortcut keys.

To run a macro, click the button on the Quick Access Toolbar, press the keyboard shortcut, or you can run the macro from the Macros list.

  1. Click View > Macros > View Macros.

    View Macros command

  2. In the list under Macro name, click the macro you want to run.

  3. Click Run.

To make a macro from one document available in all new documents, add it to the Normal.dotm template.

  1. Open the document that contains the macro.

  2. Click View > Macros > View Macros.

    View Macros command

  3. Click Organizer.

    Organizer button in the View Macros box

  4. Click the macro you want to add to the Normal.dotm template, and click Copy.

  1. Click File > Options > Customize Ribbon.

  2. Under Choose commands from, click Macros.

  3. Click the macro you want.

  4. Under Customize the ribbon, click the tab and custom group where you want to add the macro.

If you don’t have a custom group, click New Group. Then click Rename and type a name for your custom group.

  1. Click Add.

  2. Click Rename to choose an image for the macro and type the name you want.

  3. Click OK twice.

  1. On the Developer tab, in the Code group, click Macros.

  2. In the Macro name box, type a name for the macro.

    Note: If you give a new macro the same name as a built-in macro in Word, the new macro actions will replace the built-in macro. To view a list of built-in macros, click Word Commands in the Macros in list.

  3. In the Macros in list, click the template or document in which you want to store the macro.

    To make your macro available in all documents, be sure to click Normal.dotm.

  4. Click Create to open the Visual Basic Editor.

After you open the Visual Basic Editor, you may want more information about working with Visual Basic for Applications. For more information, click Microsoft Visual Basic Help on the Help menu or press F1.

You can record a sequence of actions, or you can write a macro from scratch by entering Visual Basic for Applications code in the Visual Basic Editor.

Note: To work with macros in Office Word 2007, you need to show the Developer tab.

  1. Click the Microsoft Office Button Office button image, and then click Word Options.

  2. Click Popular.

  3. Under Top options for working with Word, select the Show Developer tab in the Ribbon check box.

    Note: The Ribbon is a component of the Microsoft Office Fluent user interface.

  1. On the Developer tab, in the Code group, click Record Macro.

    Code group on the Developer tab

  2. In the Macro name box, type a name for the macro.

    Note: If you give a new macro the same name as a built-in macro in Office Word 2007, the new macro actions will replace the built-in macro. To view a list of built-in macros, on the Developer tab, in the Code group, click Macros. In the Macros in list, click Word Commands.

  3. In the Store macro in box, click the template or document in which you want to store the macro.

    Important: To make your macro available in all documents, be sure to click Normal.dotm.

  4. In the Description box, type a description of the macro.

  5. Do one of the following:

    • Begin recording    To begin recording the macro without assigning it to a button on the Quick Access Toolbar or to a shortcut key, click OK.

    • Create a button    To assign the macro to a button on the Quick Access Toolbar, do the following:

      1. Click Button.

      2. Under Customize Quick Access Toolbar, select the document (or all documents) for which you want to add the macro to the Quick Access Toolbar.

        Important: To make your macro available in all documents, be sure to click Normal.dotm.

      3. Under Choose commands from dialog box, click the macro that you are recording, and then click Add.

      4. To customize the button, click Modify.

      5. Under Symbol, click the symbol that you want to use for your button.

      6. In the Display name box, type the macro name that you want to display.

      7. Click OK twice to begin recording the macro.

        The symbol that you choose is displayed in the Quick Access Toolbar. The name that you type is displayed when you point to the symbol.

    • Assign a keyboard shortcut    To assign the macro to a keyboard shortcut, do the following:

      1. Click Keyboard.

      2. In the Commands box, click the macro that you are recording.

      3. In the Press new shortcut key box, type the key sequence that you want, and then click Assign.

      4. Click Close to begin recording the macro.

  6. Perform the actions that you want to include in the macro.

    Note: 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 select text. For more information about selecting text by using the keyboard, see Select text.

  7. To stop recording your actions, click Stop Recording in the Code group.

Change the keyboard shortcut for a macro

  1. Click the Microsoft Office Button Office button image, and then click Word Options.

  2. Click Customize.

  3. Next to Keyboard shortcuts, click Customize.

  4. In the Categories list, click Macros.

  5. In the Macros list, click the macro that you want to change.

  6. In the Press new shortcut key box, type the key combination that you want to choose.

  7. Check the Current keys box to make sure that you aren’t assigning a key combination that you already use to perform a different task.

  8. In the Save changes in list, click the option that matches where you want to run your macro.

    Important: To make your macro available in all documents, be sure to click Normal.dotm.

  9. Click Close.

  1. On the Developer tab, in the Code group, click Macros.

    Code group on the Developer tab

  2. In the list under Macro name, click the macro that you want to run.

  3. Click Run.

  1. On the Developer tab, in the Code group, click Macros.

    Code group on the Developer tab

  2. In the Macro name box, type a name for the macro.

    Note: If you give a new macro the same name as a built-in macro in Office Word 2007, the new macro actions will replace the built-in macro. To view a list of built-in macros, click Word Commands in the Macros in list.

  3. In the Macros in list, click the template or document in which you want to store the macro.

    To make your macro available in all documents, be sure to click Normal.dotm.

  4. Click Create to open the Visual Basic Editor.

After you open the Visual Basic Editor, you may want more information about working with Visual Basic for Applications. For more information, click Microsoft Visual Basic Help on the Help menu or press F1.

To make quick work of tasks that you do often, in the desktop version of Word you can bundle the steps into macros that run with a single click. In Word for the web, you have to step through such tasks manually.

If you have Word, first click Open in Word to open your document in Word.

Image of the Open in Desktop App command

Then follow the instructions for the desktop version of Word.

When you run the macro in Word and save the document, you’ll see the results of the macro when you reopen your doc in Word for the web.

Need more help?

In Word, you can automate frequently used tasks by creating and running macros. A macro is a series of commands and instructions that you group together as a single command to accomplish a task automatically.

Contents

  • 1 How do you use macros in Word?
  • 2 What is a macro and how is it used?
  • 3 Why we use macro in MS Word?
  • 4 Where do I find macros in Word?
  • 5 How do you write macros?
  • 6 Can macros have numbers?
  • 7 Why macros are useful?
  • 8 What is macros in MS Word PDF?
  • 9 What is macros and how do you count them?
  • 10 Can macro names contain spaces?
  • 11 How do I remove macros from a Word document?
  • 12 Why do my Word macros keep disappearing?
  • 13 What is a macro in Word 2010?
  • 14 What is an example of a macro?
  • 15 How do I make a macro on my computer?
  • 16 What are the steps to run a macro?
  • 17 What is macro in C Tutorialspoint?
  • 18 Can macros contain viruses?
  • 19 How long can macro names be?
  • 20 What are the disadvantages of macros?

How do you use macros in Word?

When you have a repetitive series of tasks to perform, you can record those tasks as a macro.

  1. Place the cursor where you want to start recording the macro.
  2. Click the Record Macro button.
  3. Give the macro a name.
  4. Click the Keyboard button.
  5. Press the keyboard shortcut keys that you want to use.
  6. Click Assign.
  7. Click Close.

What is a macro and how is it used?

A macro is used to automate a task that you perform repeatedly or on a regular basis. It is a series of commands and actions that can be stored and run whenever you need to perform the task. You can record or build a macro and then run it to automatically repeat that series of steps or actions.

Why we use macro in MS Word?

Macros – a little known tool in Microsoft Word – allow you to automate frequently used formatting settings. Macros are especially useful when you find yourself making the same formatting changes over and over again to multiple documents.

Where do I find macros in Word?

Here’s how you can find macros and VBA modules in your document: In Word or Excel, click View > Macro > View Macros. In PowerPoint, click View > Macro.

How do you write macros?

Record a macro
On the Developer tab, click Record Macro. Optionally, enter a name for the macro in the Macro name box, enter a shortcut key in the Shortcut key box, and a description in the Description box, and then click OK to start recording.

Can macros have numbers?

Macro names should only consist of alphanumeric characters and underscores, i.e. ‘a-z’ , ‘A-Z’ , ‘0-9‘ , and ‘_’ , and the first character should not be a digit.

Why macros are useful?

Macros automate common and repetitive keystrokes that you use in Excel to create and edit spreadsheets. By reducing the number of keystrokes required to perform common commands, macros speed up your production and reduce the time you have to spend staring at an electronic spreadsheet each day.

What is macros in MS Word PDF?

Macros enable you to automate routine operations and tasks in Microsoft programs. A macro is a small program that records the actions you take to complete a specific task, for example, adjusting the page layout to a specific format. You then run the macro to apply all of the recorded actions in just a single click!

What is macros and how do you count them?

Macros—short for macronutrients—include carbs, proteins, and fats. Simply put, counting macros involves tallying up how many grams of each macronutrient type you consume each day, aiming for specific targets. The method is a key component of eating plans like the keto diet.

Can macro names contain spaces?

Macro names must begin with a letter and cannot contain spaces, symbols, or punctuation marks. After the first letter, you can use more letters, numbers, or the underscore character, but the maximum length is 80 characters.

How do I remove macros from a Word document?

To delete a macro, follow these steps:

  1. Press Alt+F8. Word displays the Macros dialog box.
  2. From the list of macros, select the macro you want to delete. The Delete button becomes available.
  3. Click on Delete.
  4. Repeat steps 2 and 3 for each macro you want to delete.
  5. Click on Close when finished.

Why do my Word macros keep disappearing?

That could happen if the original file was moved or renamed, so that there was no file with that exact name, and then Word was started. If you have a backup of that file or of the whole drive, restore it to replace the current copy.

What is a macro in Word 2010?

A macro is a teensy program you can write in Word 2010 that automates things, such as repetitive keystrokes or tasks. You start making a macro by recording it.

What is an example of a macro?

Macro is defined as something that covers a large amount, or is large in size. An example of macro is the study of the key driving aspects of an economy; macro economics. An example of macro is a very close up photograph of an ant; a macro photograph.

How do I make a macro on my computer?

How do I create macros?

  1. Using the mouse that you want to configure, start Microsoft Mouse and Keyboard Center.
  2. In the list under the button that you want to reassign, select Macro.
  3. Click Create a new Macro.
  4. In the Name box, type the name of the new macro.
  5. Click in Editor, and enter your macro.

What are the steps to run a macro?

Right-click the macro in the Navigation Pane, and then click Design View. On the Design tab, in the Tools group, click Single Step. Click Run. If the macro is a new or edited macro, you will be prompted to save the macro before you can run it.

What is macro in C Tutorialspoint?

CServer Side ProgrammingProgramming. Macro substitution is a mechanism that provides a string substitution. It can be achieved through “#deifne”. It is used to replace the first part with the second part of the macro definition, before the execution of the program.

Can macros contain viruses?

A macro virus is a computer virus written in the same macro language as the software it infects — common victims include Microsoft Excel and Word. Because they target software rather than systems, macro viruses can infect any operating system. So a macro virus can infect a PC or Mac.

How long can macro names be?

The maximum length of a macro name is hard-coded at 20 characters and cannot be changed with compile-time definitions. If you declare a macro name that (not counting the curly braces) is longer than 20 characters, the following error will be printed and the excess characters will become the value of an undefined name.

What are the disadvantages of macros?

The disadvantage of the macro is the size of the program. The reason is, the pre-processor will replace all the macros in the program by its real definition prior to the compilation process of the program.

A macro is a series of commands that is recorded so it can be played back (executed) at a later time. Macros are great for reducing the amount of work you have to do on a series of steps that you perform frequently. Here’s how to create and test a macro in Microsoft Word.

Instructions in this article apply to Word for Microsoft 365, Word 2019, Word 2016, Word 2013, and Word 2010.

Why Use a Macro

With a macro, you can get the same results by clicking a command instead of going through all the steps. Some ways to use macros to increase your productivity include:

  • Insert your company logo and name in a particular typeface.
  • Insert a table that you need to create regularly.
  • Format a document with certain characteristics, such as page numbering and double-spaced paragraphs.

Creating and using macros is a learned skill but the resulting efficiency is well worth the effort.

Create a Macro

There are more than 950 commands in Word, most of which are on menus and toolbars and have shortcut keys assigned to them. Some of these commands, however, are not assigned to menus or toolbars by default. Before you create your own Word macro, check to see if it exists and can be assigned to a toolbar.

To see the commands available in Word, follow these steps:

  1. Select the View tab.

  2. Choose Macros.

  3. Select View Macros.

    Or, press the Alt+F8 shortcut key to access the Macros dialog box.

  4. Select the Macros in drop-down arrow and choose Word Commands.

  5. In the alphabetical list of command names, highlight a name to display a description of the command at the bottom of the Macros dialog box under the Description label.

If the command you wish to create exists, don’t duplicate it with your own Word macro. If it doesn’t exist, proceed with creating your Word macro.

Plan for Effective Word Macros

The most important step in creating effective Word macros is careful planning. This planning includes having a clear idea of what you want the Word macro to perform, how it will make your future work easier, and the circumstances under which you intend to use it.

Once you have these things in mind, plan the actual steps. This is important because the recorder will remember everything you do and include it in the macro. For example, if you type something and then delete it, every time you run that macro, Word will make the same entry and then delete it, making a sloppy and inefficient macro.

When you plan your macros, here are some things to consider:

  • Plan the commands and the order in which you want the macro to perform the commands.
  • Know the shortcut keys for the commands you plan to use. This is particularly important for navigation as you aren’t able to use the mouse for navigation within the document area when you run the recorder. Further, you will create a leaner macro if you use a shortcut key rather than the arrow keys.
  • Plan for messages that Word might display and that will stop the macro.
  • Use as few steps as possible to keep the macro efficient.
  • Do at least one test run before you start recording.

After you’ve planned your Word macro and done a run-through, you’re ready to record it. If you’ve planned your macro carefully, recording it for later use will be the easiest part of the process. The only difference between creating a macro and working on the document is that you have to press a few extra buttons and make a couple of selections in dialog boxes.

Record the Macro

When you start recording a macro, the mouse pointer has a small icon that looks like a cassette tape beside it, indicating that Word is recording your actions. You can then follow the steps you laid out in the planning stage. Once you are done, press the Stop button (it is the blue square on the left). Once you press the Stop button, your Word macro is ready to use.

Here’s how to record a macro.

  1. Go to the View tab, select Macros, then choose Record Macro to open the Record Macro dialog box.

  2. In the Macro Name text box, type a unique name.

    Names can contain up to 80 letters or numbers (no symbols or spaces) and must begin with a letter. The name should be unique so that you can determine what it does without having to refer to the description.

  3. In the Description text box, enter a description of the actions the macro performs.

  4. Select whether you want the macro to be available in all documents or only in the current document. If you choose to limit the availability of the command, highlight the document name in the Store Macro in drop-down menu.

    By default, Word makes the macro available to all your documents, and you will probably find that this makes the most sense.

  5. When you have entered the information for the macro, select OK. The Record Macro Toolbar appears in the upper-left corner of the screen.

To pause the recording, select the Pause Recording/Resume Recorder button (it is the one on the right). To resume recording, select it again.

Test the Macro

The purpose behind creating macros in Word is to speed up your work by putting repetitive tasks and complex sequences of commands at your fingertips. Make sure your macro runs as intended by testing the macro.

  1. To run the macro, press the Alt+F8 shortcut key to display the Macros dialog box.

  2. Highlight the macro in the list, then select Run.

If you don’t see your macro, make sure the correct location is in the Macros in box. 

Create Keyboard Shortcuts for Macros

If you created several macros, searching through the Macros dialog box takes time. If you assign macros a shortcut key, you can bypass the dialog box and access your macro directly from the keyboard in the same way you use shortcut keys to access other commands in Word.

  1. Select File, then choose Options.

  2. In the Word Options dialog box, go to the left pane and select Custom Ribbon.

  3. Select Customize.

  4. In the Categories list, scroll down to Macros and select the macro for which you want to create a new shortcut.

    If the macro currently has a shortcut key assigned to it, the shortcut will appear in the box below the Current keys label.

  5. If no shortcut key has been assigned to the macro, or if you want to create a second shortcut key for the macro, select the Press new shortcut key text box.

  6. Enter the shortcut key you want to use to access your macro.

    If the shortcut key is assigned to a command, a message says Currently assigned to followed by the name of the command. Either reassign the shortcut key by continuing, or select a new shortcut key.

  7. Select the Save changes in drop-down arrow and choose Normal to apply the change to all documents created in Word.

    To use the shortcut key only in the current document, select the document name from the list.

  8. Select Assign.

  9. Select Close to save your changes.

Thanks for letting us know!

Get the Latest Tech News Delivered Every Day

Subscribe

The Microsoft Office suite is one of the most popular office solutions. From Word and Excel to PowerPoint – the practical applications for writing, calculating, and presenting have been proving their worth for years. But many users are not even aware of the range of features that they provide. For instance, MS Office programs include a function that allows you to create, save, and execute macros in order to automate certain tasks and processes. Especially for regularly recurring workflows, this feature lets you save valuable time and effort.

But what role do macros play in Word and how do these command sequences work exactly? Also find out how to create macros in Word and integrate them into your documents.

Contents

  1. What is a Word macro?
  2. How Do Macros Work in Word?
  3. Creating Macros in Word: How it Works
    1. Recording Word Macros Executed by Button
    2. Creating Word Macros Executed via Key Combination
    3. Executing Word Macros
    4. Adding macro buttons to a Word tab ribbon
    5. Importing Existing Macros in Word
  4. Word Macros: Examples of Useful Command Sequences
    1. Word Macro for Automatically Determining the Average Sentence Length
    2. Word Macro Example: Correcting Transposed Letters
    3. Macro Code for Removing All Hyperlinks

What is a Word macro?

Macros are considered a standard feature in programming as well as the use of computer programs. They are basically subprograms that developers and users can create to save sequences of commands or operating instructions, which can then be started with a simple action. When faced with many regularly recurring tasks, Microsoft Word is typically an application that benefits from the option to automate work steps.

For this reason, the Editor (as well as Access, Excel or PowerPoint, for example) include an integrated tool for recording and executing custom Word macros. The script language Visual Basic for Applications (VBA), likewise developed by Microsoft, serves as the recording language here.

Note

The event-driven programming language VBA replaced the mutually incompatible macro languages of the various Microsoft Office programs in the mid-1990s. Thanks to this standardized solution, cross-program command chains can also be created and run to transfer data from a Word document into an Excel table with a single click, for example.

How Do Macros Work in Word?

Creating macros in Word may sound like a task for experienced programmers at first. After all, writing new program code in a special programming language is not often among the core skills of the average Word user. However, the fact that creating and using Word macros is possiblewithout any programming knowledge at all is thanks to the integrated macro tool. Known as a macro recorder, this tool makes writing code completely unnecessary. To create a new macro, all the user has to do is start recording, perform the desired operating steps and commands, and then stop the recording again when the sequence is finished. The VBA code for Word macros is generated automatically; no further action is required on the part of the user.

Note

With the Visual Basic Editor, the Microsoft Office tools have integrated their own VBA development environment that allows the code of recorded macros to be viewed and edited.

You can also assign each new macro in Word with a unique key combination or button that allows the corresponding command sequence to be run at any time. In the case of buttons, these can be added to the toolbar for quick access, enabling you to start a macro with a single click. If the Word macro created is to be available in all documents, save it in the template file Normal.dotm, which is used by Word as the general template for all new text projects.

Creating Macros in Word: How it Works

If you would like to configure your own automated sequences for your Word documents, but lack the technical knowledge in the programming language VBA, you should use the option to create macros in Word using the recorder. You can find the macro tools as standard under the “Macros” section in the “View” tab. In order to make it easier to create and manage Word macros, however, it is advisable to activate the developer tools which provide you access to the Visual Basic Editor, among other features. This optional toolbox can be unlocked as follows:

  1. Open the “File” tab.
  2. Click on “Options”.
  3. Switch to the “Customize the Ribbon” section and place a checkmark in the “Developer” box (under “Main Tabs”).
Word 2016: “Customize the Ribbon” in the Word options
You can remove the developer tools from the Word ribbon at any time by deactivating the checkbox.

As soon as you have activated the “Developer” tools in the Word options, the tabunder the same name will automatically be added to the user interface. When you click on it, you will see the section for creating and managing macros in the far left of the toolbar. Find out in the following step-by-step guide how to create your own macros in Word using this quick-access menu and how you can run them at a later time.

Recording Word Macros Executed by Button

The typical solution for a new macro in Word is one that can be run by clicking a button. If you would like to create such a macro using the developer tools, first click on the “Developer” tab and then select the option “Record Macro”:

Word 2016: “Developer” tab
To open the menu for recording new Word macros, you can also press the [Alt], [L], and [R] keys consecutively.

Now enter a name for the macro and select the document you wish to create the macro for under “Store macro in:”. If you would like to create a cross-program macro, simply select the option “All Documents (Normal.dotm)”. To enable the macro to be executed in Word using a button, finally click on “Button”:

The “Record Macro” menu in Word 2016
You have the option to add individual information about the Word macro you want to create under “Description”.

Select the macro you wish to create in the left window and click on “Add”, making it also selectable in the right window. Click on it here again and then press the “Change” button. You can now assign your new Word macro any icon you wish:

Adjusting the quick-access toolbar in Word 2016
When assigning the button for the new macro, you also have the option of adding it to all Word documents (standard) or for a certain document only.

Confirm your desired button by clicking on “OK” twice. Now perform the actions you want to save in the macro. Word will record your mouse clicks as well as key strokes. However, the recorder will not save any movements or highlighting with the mouse. So if you want to select some text, for example, you will need to use the keyboard (hold down the [Shift] key and use the arrow keys).

Once you have finished the sequence for the macro, you can stop the recording via “Stop Recording”:

The “Developer” tab in Word 2016
You can also pause the recording for the Word macro temporarily: Simply use the “Pause Recording” button in the toolbar.

The key for the new Word macro will automatically be added to the toolbar for quick access:

Microsoft Word 2016: Quick-access toolbar
The quick-access toolbar also contains as standard the buttons for saving the current Word document or reversing changes.

Creating Word Macros Executed via Key Combination

You can create a Word macro that can be started using a unique key combination in essentially the same way as for macro buttons: Start the process using the “Record Macro” button in the macro menu under “Developer”, enter a suitable name, and decide whether you want to make the macro available in all documents or only in a certain project. In the final step before beginning the recording, you should choose the “Keyboard” option in order to open the menu for new hotkeys:

The “Record Macro” Word menu
If you choose a name for a new macro which already exists, Word will ask whether you wish to replace the original macro.

In the “Customize Keyboard” menu that then appears, select the macro under “Commands”. Next, click on the “Press new shortcut key” field with the left mouse button and press your desired key combination. Here it is important to press these keys simultaneously. In the following Word macro example, we used the [Ctrl], [Shift], and [#] keys.

Word 2016: “Customize Keyboard” menu
Word will tell you whether a chosen key combination already exists or is not yet assigned – as in this example.

Under “Save changes in”, you can define whether the key combination should be valid universally (“Normal”) or only for a certain Word document; to confirm your choice, click on the “Assign” button. As soon as you close the menu, the macro recording will start.

Executing Word Macros

Once you have created a macro, you can start it at any time using the defined execution option. You only need to use the define key combination or click on the corresponding button in the quick-access menu (in the top left). You can also run your Word macros using the macro list by following the steps below:

  1. Click on the “Macros” button under the “Developer” tab or alternatively on “Macros” in the menu under the “View” tab, and then on “View Macros”.
  2. Select the desired macro from the list using a left mouse click.
  3. Now press “Run”.
List of available macros in Word 2016
Once you have activated the developer tools, you can open the selected Word macro in the Visual Basic Editor by clicking on “Edit”.

Adding macro buttons to a Word tab ribbon

If the macro icon is too small for you in the quick-access toolbar or if you would like to add a button for a macro executable via key combination, you can also integrate a macro button into the ribbon of any tab. To do so, simply create a user-defined group for the tab and add the desired macro to it. You can do both in the “Customize Ribbon” menu in the Word options (accessibly via “File” -> “Options”).

Creating a user-defined group:

In the right window under “Customize Ribbon”, select the tab in which you wish to create the new group and then click on the “New Group” button. In addition to the standard groups here, the entry “New Group (User-Defined)” will now appear. Click on this and then press “Rename” to give the group a suitable name as well as an icon:

Word 2016: Customizing the ribbon for the “Start” tab
World will only display the selected symbol if the width of the program window is reduced and the group is collapsed for this reason.

Integrating a Word macro into a user-defined group:

After creating a user-defined group for a tab’s ribbon, you can now add any number of Word macros to this group. First click on the “Macros” option in the left menu section under “Choose commands from:” and then on the Word macro you wish to integrate. In the right menu window, now click on the user-defined group before finally pressing the “Add” button:

Adding Word macros to a tab
If you would like to remove a macro from a user-defined ribbon group again, select it in the right menu window and then click on the “Remove” button.

Close the Word options and open the tab you added the macro button to. You should now see this in the group you created in the ribbon:

Word 2016: Customized ribbon
In standard tabs, new groups are typically added to the right of existing groups. But you can also adjust the order and position the button elsewhere.

Importing Existing Macros in Word

You may also find yourself in the situation in which you already have VBA macros, but they are not available in your Word installation. This could be the case, for instance, if you created these macros on another device or received them from another person. Plus, there are various online sources where you can find a wide range of macros. Microsoft Word offers you the option to import ready-made command chains for use in your program. The tool for this is the Visual Basic Editor mentioned earlier. It can be opened via the key combination [Alt] + [F11] or alternatively using the “Developer” tab.

The next steps depend on whether you are importing a finished macro file or pure macro code.

Importing ready-made macro files (.frm, .bas, .cls):

If you have a complete macro as a file, you can import it into your Word installation in just a few steps. First, select the document you want to add the macro to in the Project Explorer. If you can’t find the explorer in the code editor, you can open it by selecting the “View” tab and pressing the “Project Explorer” menu item. In the file manager, now click on your current or another Word project if the macro should only be applied to one document. If you select the project “Normal”, the Word macro will be imported for all documents:

Project Explorer in the Visual Basic Editor
When you no longer need the Project Explorer, you can close it at any time by clicking on the cross in the top right.

To import the macro, click on “File” and then “Import File”. Specify the storage location for the macro file and press “Open” to start the import process.

The “Import File” option in the Visual Basic Editor
If you have created a Word macro, you can also export it as a file here using the button under the same name.

Importing macro code:

If you only have the code for a certain macro, other steps have to be taken for importing. Here too, you start by selecting the document you wish to add the automatic command sequence to. Open the explorer and double-click on the entry “ThisDocument” (in the subfolder “Microsoft Word Objects”) for the respective document or under “Normal” (to save the macro in the universal template):

Microsoft Word 2016: Project Explorer
When you select the project “Normal”, Word will save the macro in the universal template Normal.dotm.

In the code window that appears next, copy the macro code and then click on the “Save” button. If you selected a specific Word document in the previous step, you will be notified that you will have to save it as a “Word document with macros”. Then click on “No” and select the corresponding entry under the “File Type” list. Finally, click on “Save” to generate the new file format:

Changing the Word file type
To save an imported macro in the current Word document, you will need to change the format of your current document. When saving in the universal template, however, this is not necessary.

Word Macros: Examples of Useful Command Sequences

Now that you know what a Word macro is and how to use macros in Word (creating, running, and importing macros), we can explain the purpose of these command chains for automation in Microsoft’s text editor using a number of specific Word macro examples.

Word Macro for Automatically Determining the Average Sentence Length

There are various web tools you can use to analyze your texts – such as to ascertain the average length of your sentences. Using the right macro, you can also find this out directly in Word. The following code automatically looks at all the sentences in your document and divides the total word count by the number of sentences. The macro then displays the average length in a text popup (“Average Words Per Sentence:”):

Sub CountWords()
Dim s As Range
Dim numWords As Integer
Dim numSentences As Integer
numSentences = 0
numWords = 0
For Each s In ActiveDocument.Sentences
numSentences = numSentences + 1
numWords = numWords + s.Words.Count
Next
MsgBox "Average Words Per Sentence: " + Str(Int(numWords / numSentences))
End Sub

Word Macro Example: Correcting Transposed Letters

Anyone who regularly types texts on a computer will know just how quickly typos like transposed letters occur. But these errors can be quickly corrected. Using the following macro, you only need to place the marker in front of the erroneous pair of letters. Running the macro via key combination or button then allows the letters to be swapped around automatically:

Sub TransposeCharacters()
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Cut
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Paste
End Sub

Macro Code for Removing All Hyperlinks

Whenever you include website addresses in your texts, Word will automatically change them into clickable hyperlinks to the corresponding sites. But if you don’t want your document to contain these hyperlinks, you usually have to delete the links individually. The following Word macro example saves you a whole lot of work by automatically removing the first hyperlink found in the document. You can therefore run the macro as often as necessary until all the hyperlinks are gone:

Sub RemoveHyperlinks()
'On Error Resume Next
Dim x As Variant
For Each x In ActiveDocument.Hyperlinks
Selection.WholeStory
Selection.Range.Hyperlinks(1).Delete
Next x
End Sub

Click here for important legal disclaimers.

When using Microsoft Word, you may feel the need to repeat a specific action multiple times. This may involve reusing preset text or inserting specific text with intricate formatting. It can be a chore, and you may be wishing for an easier way to do it. Thankfully, there is one! By making use of Word’s macros, you can automate repetitive actions and make your life simpler.

What Are Macros?

So, what are macros? The best way to think of macros is as a series of instructions. You set out a series of steps that you want Word to automate, then tell Word to perform those steps whenever you like. This makes automation very easy, and can save a lot of time and effort. The easiest way to create a macro is to allow Word to record your actions, then physically perform your desired actions within the document. Once recorded, you can tell Word to repeat what you did at any time.

Making a Macro

So now that we know what they do, let’s learn to make a macro in Microsoft Word! In this example we’ll be creating a macro that automatically creates a table. This might be a useful feature if you occasionally see yourself needing to create a new table without manually making a new one or copy-pasting an existing table.

First, we need to tell Microsoft Word how to make our table. To do this, we click on “View,” then “Macros,” then “Record Macro.”

word-macro-create

We name our macro here. For this example we’ll call it “CreateTable.”

word-macro-name

Underneath the naming box are two buttons, “Button” and “Keyboard.” This is where you pick if you want to activate your macro via a button within Word or by pressing a hotkey on your keyboard.

Selecting the Button Option

If you select “Button,” you’ll be taken to a new popup window. It may look confusing at first, but it’s just Word allowing you to add the button to the Quick Access bar. This is where we want our button, so we’ll select the macro and click “Add >>” to add it to the list on the right.

word-macro-button-add

With the macro still selected, click “Modify…” at the bottom of the list.

word-macro-button-modify

Here you can choose what icon your button uses. Pick something that suits your macro, then OK out of all windows.

word-macro-button-icon

Selecting the Keyboard Option

If you select the keyboard option, you can define which hotkey to assign the macro to. It’s compatible with quite a few combinations, such as Ctrl + [Key] and Ctrl + Shift + [Key], so pick out a hotkey that suits you. Word will let you know if anything is currently assigned to that hotkey so you don’t interfere with existing shortcuts. Once you’ve found the perfect key combination, click “Assign.”

word-macro-keyboard-assign

Recording the Macro

Now that you have set up the method of activation, Microsoft Word will begin recording your actions. While it’s recording, any actions you now perform in the document will be remembered in the macro. In this example, we create our table and fill it out with the essential fields. Because our actions are being recorded, we should be careful and not make any mistakes!

word-macro-table-example

Once the table is done, we click “View,” then “Macro” again, and then click “Stop recording.”

word-macro-stop

Now that our macro is recorded, we can make this table at any time we like. If we assigned it to a hotkey on the keyboard, we can press those keys to insert a table. Likewise, if we made a button for it, we can find that button in the Quick Access bar.

word-macro-button-bar

Regardless of which method we selected for the macro, our table is replicated when we activate it. Now we can recreate our base table with little hassle!

word-macro-table-duplicate

Deleting a Macro

When your macro has outlived its use, you can get rid of them by simply clicking “View,” then “Macros,” then “View Macros.”

word-macro-view

Select the macro you don’t want anymore, then click “Delete.”

word-macro-delete

Macro Safety

While macros can be used to make life easier, they can also have nefarious intents! Never run macros that have come from an untrusted source or download a Word document attached to a suspicious email. “Macro viruses” can be a real problem, so make sure you stay safe when using them.

Macros Made Easy

When you need to perform repetitive actions in Word, a macro can come in great use. Now you know how to make a keyboard or button macro, how to record it, and how to use it once it’s made.

Do you see yourself using macros a lot? Do you already? Let us know below.

Simon Batt

Simon Batt

Simon Batt is a Computer Science graduate with a passion for cybersecurity.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Понравилась статья? Поделить с друзьями:
  • What are labels used for in excel
  • What are key word phrases
  • What are justifications in word
  • What are headers in microsoft word
  • What are headers and footers in word