Create and run a macro in Word

If you work with Microsoft Word a lot and you find yourself doing the same things over and over, make a macro† Macro is an abbreviation of the word macro instruction, which means a set of instructions to accomplish a task.

The great thing about creating macros in Word is that you don’t have to know how to program† If you can press record and stop, you can.

Aren’t macros dangerous?

Have you heard that macros are bad because they can contain viruses† While you should be careful about opening Office documents belonging to unknown people as they may have malicious macros, that’s not a problem here. You make your own macro so you know it’s not a virus.

Record a macro in Word

For this example, you will create a macro in Word to insert your signature at the end of a document.

  1. With Word open go to the Vision tab.
  2. Select the down arrow below the Macros knob.
  3. Select Record macro… a new window will open.
  1. In the Macro Name: enter a meaningful name for the macro. Spaces are not allowed. Use an underscore or dash.
  2. In the Save macro in: drop-down list, you can select which documents you want this macro to be used. If you choose All Documents (Normal.dotm), the macro will now be available to you in any new Word document you create. If you choose one document, this only applies to that one document. It is usually best to choose All documents
  1. In the Description: field, write down what the macro does. This is a simple macro with a descriptive name, but as you become more familiar with macros, you’ll be doing more complex things, so a description is always a good idea.
  2. You can choose Assign macro to either a button you create with the Knob or hotkeys that you can choose with the Keyboard knob. There are already many keyboard shortcuts for Word, so a button might be best. Select Knob† A new window will open with the name word options
  1. This is where you assign the macro a button on the Word ribbon. Select Customize ribbon
  2. In the Choose assignments from: drop-down list, select Macros† This shows us our macros in the area below.
  1. You need somewhere on the ribbon to place the macro. Select for this example House in the Main Tabs area. Then select New group
  2. Select rename so you can give it a meaningful name.
  3. In the rename window, select one of the icons to display the group, then enter My macros in the Display name field.
  4. Select Okay to apply it. You see the change in the Main tabs Surface.
  1. With the new My Macros selected in the Main Tabs area, select the Normal.NewMacros.Insert_Signature macro.
  2. Select To add to insert it in the My Macros group.
  1. Of course you want to rename it. With the macro selected in the Main Tabs area, select Renaming…
  2. In the Rename window, select an icon and enter a simple name in the Display Name: field.
  3. Select Okay to make the change. You will see the change in the Main Tabs area.
  4. Select Okay under the Main Tabs area to finish creating the button for the macro.
  1. Go ahead and create any signature block you want. Include a scan of your signature or other images. Whatever you want. Once you’ve done that, select the down arrow below the Macros knob.
  2. Select Stop recording† That is it. Your Insert Signature macro has been created.
  1. Test it by finding the Insert signature button you created on the Home tab and select it. Your signature block should magically look exactly like you designed it.

How do you write a macro?

For most macros, the shooting method is the most efficient way to create them. Ultimately, you want to do something more complex. To do this, the macro must be written in the Visual Basic for Applications (VBA) language. We have the best VBA guide for beginners, so bookmark it. Let’s create a macro to give us the average words per sentence so we can see when we’re being wordy.

  1. You need access to the Developer tab that is hidden by default in Word. In the top left corner of Word, select File
  1. Select near the bottom left corner Options
  1. In the window that opens, select Customize ribbon
  2. On the right, look for Developer and put a check next to it.
  3. Select Okay to close the window. The Developer tab is now displayed.
  1. Select the Developer tab.
  2. Select the Macros knob.
  1. Enter a meaningful name Macro Name: Leave the Macros in: as Normal.dotm, so it applies to all Word documents. Always enter a description in the Description: Surface.
  2. Select To create† The Microsoft Visual Basic for Applications development tool opens.
  1. The code shown in the green rectangles below should already be there with some blank space in between. Copy and paste the following code into that space:

Dim as range
Dim numWords as an integer
Dim num Sentences As Integer
numSentences = 0
number of Words = 0

For each s in ActiveDocument.Sentences
numSentences = numSentences + 1
numWords = numWords + s.Words.Number
Next one

MsgBox “Average words per sentence” + Str(Int(numWords / numSentences)) + “. Less than 15 is best.”

  1. Select the Run button to test the code. If it doesn’t work as expected, edit the code until it works the way you want.
  1. Select the Save button and close the development window.
  1. Create a button in the Word ribbon using the same method shown in the instructions above for recording a macro.
  2. Find the button you just created and test it.

My macro doesn’t work when I save my Word document

By default, Word is saved with the .docx file extension, which prevents macros from running automatically. For the macro to run, you must change the file type to Word Macro-Enabled Document (*.docm).

This file type exists in part to combat macro security vulnerabilities. If you see this file extension on a document you did not expect to receive, be suspicious.

What else can I do with macros?

You can create macros in Excel, Outlook, even PowerPoint. Anything you’re currently doing manually, you should be able to record or write a macro to do it. Using macros in Word along with great Windows keyboard shortcuts will increase your productivity tenfold.

Leave a Reply

Your email address will not be published.