Automating Tasks with Macros in Microsoft Word

In this tutorial, we will show how to automate tasks with macros in Microsoft Word.

Automating Tasks with Macros in Microsoft Word
Image by Editor
 

Microsoft Word macros can save significant time by automating repetitive tasks. If you frequently perform repetitive tasks in Microsoft Word, like formatting documents, inserting standard tables, or applying specific styles, then macros can save you time.

In this tutorial, we will show how to automate tasks with macros in Microsoft Word.

What Are Macros?

Macros are recorded sequences of instructions and actions written in VBA (Visual Basic for Applications) that automate tasks in Word. You can play back whenever needed. It can be triggered by a shortcut key, toolbar button, or directly from the Developer tab. They’re particularly useful for:

  • Formatting text consistently.
  • Inserting frequently used content.
  • Automating multi-step processes.
  • Customizing Word to fit your workflow.

Step 1: Enable the Developer Tab

To create or access macros, you need to enable the Developer tab.

  • Go to File tab >> select Options.

Automating Tasks with Macros in Microsoft Word

  • In the Word Options box >> select Customize Ribbon.
  • Check the box next to the Developer in the right panel.
  • Click OK.

Automating Tasks with Macros in Microsoft Word

Now, you’ll see the Developer tab on the ribbon.

Automating Tasks with Macros in Microsoft Word

Step 2: Record Macro

Let’s create a simple macro that applies a heading, formats text as bold, increases font size, and sets alignment.

  • Place your cursor where you want to apply the formatting.
  • Go to the Developer tab >> select Record Macro.
  • In the Record Macro box;
    • Insert Macro name: BoldHeading.
    • Choose Store macro in: All Documents (Normal.dotm).
    • Click OK.

Automating Tasks with Macros in Microsoft Word

  • Start recording.
  • Make your formatting changes.
    • Apply Heading.
    • Apply Bold format.
    • Change Font.
    • Change Alignment.
  • Go to the Developer tab >> click Stop Recording.

Automating Tasks with Macros in Microsoft Word

Word allows you to record macros without writing code.

Step 3: Run the Macro

There are several ways to run a macro. You can directly run the macro, or you can assign keyboard shortcuts or buttons.

  • Place your cursor where needed.
  • Go to the Developer tab >> select Macros.
  • In the Macros box;
    • Select the macro BoldHeading.
    • Click Run.

Automating Tasks with Macros in Microsoft Word

Output:

Automating Tasks with Macros in Microsoft Word

Step 4: Save Macros: Use .DOCM Format

When saving a document with macros, you will need to use the .docm format.

  • Go to the File tab >> select Save As.
  • Select Word Macro-Enabled Document (*.docm).
  • Click Save.
  • This format ensures your macros are preserved and executable.

Automating Tasks with Macros in Microsoft Word

Edit the Macro (Using VBA)

You can edit the macro to make changes or write advanced logic. Let’s add the color to the heading.

  • Go to the Developer tab >> select Macros.
  • In the Macros box;
    • Select BoldHeading >> click Edit.

Automating Tasks with Macros in Microsoft Word

  • This opens the VBA Editor, where you can edit the code.
Sub BoldHeading()
'
' BoldHeading Macro
'
'
    Selection.Style = ActiveDocument.Styles("Heading 1")
    Selection.Font.Size = 24
    Selection.Font.Bold = wdToggle
    Selection.Font.Color = RGB(0, 128, 0)  ' Add this line for green color
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
End Sub

Automating Tasks with Macros in Microsoft Word

You’ll need to edit the macro code directly rather than re-recording it to add color to the text.

  • Go back to the word.
  • Run the BoldHeading macro again.
  • It will update the code and add green color to the formatting.

Automating Tasks with Macros in Microsoft Word

Add a Keyboard Shortcut

You can assign a button or keyboard shortcuts for frequently used macros.

Insert Button:

  • Open the Record Macro dialog box,
  • Select Button.

Automating Tasks with Macros in Microsoft Word

  • It will open the Word Options box >>select Quick Access Toolbar.
  • Select Normal.NewMacros.BoldHeading >> click Add >> click OK.

Automating Tasks with Macros in Microsoft Word

  • A button will be assigned to the Quick Access Toolbar.
  • Select any text >> click on the Button.
  • It will apply the formatting to the text.

Automating Tasks with Macros in Microsoft Word

Keyboard Shortcut:

  • Open the Record Macro dialog box,
  • Select Keyboard.
  • In the Customize Keyboard box;
    • Press new shortcut key: Alt+Shift+H.
    • Click Assign.
    • Click Close.
  • Now, press shortcuts to apply the formatting.

Automating Tasks with Macros in Microsoft Word

To apply keyboard shortcuts from the macros list:

  • Go to the File tab >> select Options >> select Customize Ribbon.
  • Select New Group (Custom).
  • Select Customize Keyboard >> click Add.
  • Click OK.

Automating Tasks with Macros in Microsoft Word

  • Go to the New Tab >> select Customize Keyboard.
  • Under Categories >> select Macros.
  • From Macros >> select your macro.
  • Click in the Press new shortcut key field.
  • Press your desired key combination (e.g., Alt+Shift+H).
  • Select Assign >> click Close.

Automating Tasks with Macros in Microsoft Word

Advanced Macros: Insert Company Footer

  • Go to the Developer tab >> select Record Macro.
  • In the Record Macro box;
    • Insert Macro name: InsertCompanyFooter.
    • Choose Store macro in: All Documents (Normal.dotm).
    • Click OK.
  • Go to the Insert tab >> click on Footer >> select Blank.

Automating Tasks with Macros in Microsoft Word

  • Place your cursor in the footer area.
  • Type:
© 2025 MyCompany Inc. | All Rights Reserved
  • Press Esc twice to exit the footer area and return to the main document.

Automating Tasks with Macros in Microsoft Word

  • Go back to the Developer tab >> click Stop Recording.

Automating Tasks with Macros in Microsoft Word

  • Open a new document.
  • Go to the Developer tab >> select Macros.
  • In the Macro box;
    • Select the InsertCompanyFooter macro.
    • Click Run.

Automating Tasks with Macros in Microsoft Word

The footer is applied automatically in the new document. If you are not familiar with VBA, you can also create advanced macros to automate tasks just by recording macros.

Underlying VBA Code:

Sub InsertCompanyFooter()
'
' InsertCompanyFooter Macro
'
'
    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
        ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
        ActivePane.View.Type = wdOutlineView Then
        ActiveWindow.ActivePane.View.Type = wdPrintView
    End If
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
    Application.Templates( _
        "C:\Users\hemay\AppData\Roaming\Microsoft\Document Building Blocks\1033\16\Built-In Building Blocks.dotx" _
        ).BuildingBlockEntries(" Blank").Insert Where:=Selection.Range, RichText _
        :=True
    Selection.TypeBackspace
    Selection.PasteAndFormat (wdFormatPlainText)
    Selection.EscapeKey
    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
        ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
        ActivePane.View.Type = wdOutlineView Then
        ActiveWindow.ActivePane.View.Type = wdPrintView
    End If
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    Selection.EscapeKey
End Sub

Troubleshoot: Macro Security

For security reasons, Word may disable macros in downloaded files.

To enable them:

  • Go to the File tab >> select Info.
  • Click Enable Content (only if you trust the source).

To manage settings:

  • Go to the File tab >> select Options.
  •  Select Trust Center >> choose Trust Center Settings.
  • In the Trust Center box;
    • Select Macro Settings.
    • Select Enable all macros.
    • Click OK.
  • Click OK.

Automating Tasks with Macros in Microsoft Word

  • Macro Not Working: Try recording it again with careful attention to each step.
  • Macro Too Complex: Break it down into smaller, simpler macros.

Tips and Best Practices

  • Try to use descriptive names for macros.
  • Assign shortcut keys for frequently used macros.
  • Test macros on copies of important documents first.
  • Keep backups of important macros.
  • Use comments in your VBA code for clarity.
  • Keep macro code simple and focused on specific tasks.

Conclusion

Macros are a powerful way to automate your work in Microsoft Word. By mastering macros in Microsoft Word, you can automate your regular tasks, which will improve your efficiency with document creation and formatting. Macros can save hours of manual effort. Start with recording simple actions and gradually explore custom VBA coding as you become more confident.

Get FREE Advanced Excel Exercises with Solutions!

Shamima Sultana
Shamima Sultana

Shamima Sultana, BSc, Computer Science and Engineering, East West University, Bangladesh, has been working with the ExcelDemy project for 3+ years. She has written and reviewed 1000+ articles for ExcelDemy. She has also led several teams with Excel VBA and Content Development works. Currently, she is working as the Project Manager and oversees the day-to-day work, leads the services team, allocates resources to the right area, etc. Her work and learning interests vary from Microsoft Office Suites, and... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo