Microsoft Word 2024 Comprehensive Course — Beginner to Intermediate
W
Word 2024 Microsoft 365
📘 25 Modules Foundations Interface Formatting Graphics Tables & Charts References Collaboration Templates Macros & VBA

⚡ Module 24: Macros — Recording, Editing & Running

A macro is a recorded sequence of actions that Word plays back on command. The moment you find yourself doing the same set of steps repeatedly — formatting a heading a particular way, inserting a standard clause, cleaning up pasted text, applying a series of styles — that is a macro waiting to be built. You do not need to write a single line of code to create and use macros. The built-in recorder captures every action automatically. This module takes you from your first recorded macro to running, editing, managing, and deploying them professionally.

24.1 What Is a Macro — And When Should You Use One?

A macro in Word is a saved sequence of instructions stored as Visual Basic for Applications (VBA) code. When you record a macro, Word writes the VBA code automatically in the background. When you run it, Word re-executes those actions at computer speed — perfectly and consistently every time.

The Macro Sweet Spot — Tasks Worth Automating

TaskMacro BenefitExample
Repetitive formatting Apply a complex combination of styles, fonts, indents, and spacing with one keystroke Apply "Corp Heading 1 + Keep with next + 12pt before" in one click
Standard text insertion Insert boilerplate text, tables, or cover page elements instantly Insert the standard POPIA notice paragraph with one button press
Document cleanup A sequence of Find & Replace operations that normalise pasted text Remove double spaces, fix double paragraph marks, convert tabs to spaces — all in one click
Multi-step page setup Configure margins, orientation, headers, and footers for a specific document type instantly "Apply Landscape A4 with 1.5cm margins and no header" — one macro, one click
Report finalisation Run a sequence of pre-print checks and fixes automatically before PDF export Update all fields (F9), accept all track changes, update TOC, then export to PDF — one button

What Macros Cannot Do Well

  • Tasks that depend on reading the content of the document intelligently (use VBA with logic — covered in Module 25)
  • Tasks that require user input at runtime (use InputBox in VBA — Module 25)
  • Tasks that interact with external applications (Outlook, Excel, SharePoint) — requires VBA coding
  • Anything that requires decision-making based on conditions — recorded macros have no IF/THEN logic

24.2 Macro Security Settings

Because macros can execute code, they are a potential vector for malware. Word's macro security settings control which macros are allowed to run. Understanding these settings is essential — too restrictive and your own macros won't run; too permissive and you are vulnerable.

Accessing Macro Security

  1. File → Options → Trust Center → click Trust Center Settings…
  2. Click Macro Settings in the left panel

The Four Macro Security Levels

SettingWhat It DoesRecommended?
Disable all macros without notification All macros are silently blocked — no message appears. Documents with macros open but macros do not run. Your own saved macros also do not run. ❌ Too restrictive for most office users — your own macros stop working
Disable all macros with notification Macros are blocked by default. When a document with macros is opened, a yellow security bar appears below the Ribbon asking whether to enable content. User decides per document. Recommended for most users. Balances security with usability — you are warned and can choose. Your macros in Normal.dotm and trusted locations run without interruption.
Disable all macros except digitally signed macros Only macros signed with a trusted digital certificate from a trusted publisher run automatically. Unsigned macros show the notification bar. ✅ Recommended for enterprise environments where macros are centrally signed by IT/Dev
Enable all macros All macros run without any warning — from any document, any source. No security prompts. Never use this setting — leaves the computer fully exposed to macro malware in documents received from external sources

Trusted Locations — Running Macros Without Security Prompts

Rather than lowering your security level globally, you can designate specific Trusted Locations — folders from which all documents (including those with macros) open without security warnings. Your macro-enabled templates stored in these folders run freely.

  1. File → Options → Trust Center → Trust Center Settings → Trusted Locations
  2. Click Add new location…
  3. Browse to your templates folder (e.g., C:\Users\[Name]\AppData\Roaming\Microsoft\Templates)
  4. Tick "Subfolders of this location are also trusted" if needed
  5. Click OK
  6. Documents and templates in this folder now open without macro security warnings
Security Principle: Never add a network share, download folder, or email attachment folder as a trusted location — only add folders you fully control. The purpose of trusted locations is to remove friction for your own known-safe templates, not to create a blanket exception for all incoming files.

Developer Tab — Required for Macro Management

If not already enabled: File → Options → Customize Ribbon → tick Developer → OK. The Developer tab contains all macro recording, editing, and management tools.

24.3 Recording a Macro — Step by Step

The macro recorder watches everything you do and converts it to VBA code automatically. No coding knowledge is needed to record useful macros.

Before You Record — Planning Checklist

  1. Plan the exact steps — rehearse the actions mentally (or physically on a test document) before starting the recorder. Every step you take while recording is captured — including mistakes and corrections.
  2. Use keyboard shortcuts instead of mouse clicks where possible — mouse clicks on Ribbon buttons record correctly, but mouse clicks to select text can be unreliable in playback (the selection may not be in the same position). Use Ctrl+A, Home, End, Ctrl+Shift+End instead.
  3. Decide where to store the macro — Normal.dotm (all documents) or This Document (current file only)
  4. Choose a name and optional shortcut in advance

Recording Steps

  1. Start recording via one of these methods:
    • Developer tab → Code group → Record Macro
    • View tab → Macros group → Macros dropdown → Record Macro
    • Click the Record Macro button (circle/dot icon) in the Status Bar at the very bottom-left of the Word window
  2. The Record Macro dialog opens:
    • Macro name — type a descriptive name with no spaces (use underscores): e.g., ApplyCorpHeading1, InsertPOPIANotice, CleanupPastedText. Names are case-sensitive and cannot start with a number or contain spaces or special characters except underscores.
    • Assign macro to — Button: adds the macro to the Quick Access Toolbar immediately. Click it → the QAT customisation dialog opens → find your macro in the left list → Add → OK. The macro gets a button on the QAT.
    • Assign macro to — Keyboard: assigns a keyboard shortcut. Click it → the Customize Keyboard dialog opens → click in "Press new shortcut key" field → press your desired key combination (e.g., Ctrl+Shift+H) → verify it is not already assigned → click Assign → Close.
    • Store macro in:
      • All Documents (Normal.dotm) — macro is available in every document on this computer
      • This Document — macro is stored in the current .docm or .dotm file only (note: .docx files cannot store macros — Word will prompt you to save as .docm)
      • [Template name].dotm — if a macro-enabled template is attached to the current document, it may appear as a storage option
    • Description — type a brief description of what the macro does (optional but recommended for maintenance)
  3. Click OK — recording begins immediately. The cursor changes to a cassette tape icon (⏺), and the Record Macro button in the Status Bar changes to a Stop button.
  4. Perform every action you want the macro to record:
    • Apply styles, change fonts, set alignment
    • Type text, insert fields, insert symbols
    • Run Find & Replace operations
    • Change page setup settings
    • Insert tables, images, content controls
    • Any sequence of Ribbon and keyboard operations
  5. When all steps are complete, stop recording:
    • Developer → Code group → Stop Recording
    • View → Macros → Stop Recording
    • Click the Stop button (■) in the Status Bar
  6. The macro is saved. Test it immediately on a fresh document to confirm it works correctly.

What the Recorder Captures (and What It Misses)

✅ Recorded Correctly⚠️ Limitations / Issues
All Ribbon button clicks and menu selections
Keyboard shortcuts (Ctrl+B, Ctrl+A, etc.)
Typing text
Style application
Font changes
Find & Replace operations
Page setup changes
Tab stops and indents
Insert → Symbol, Insert → Table, etc.
Mouse-drag text selection — playback may not select the intended text
Mouse-click to position cursor — use keyboard navigation instead
Dialog box interactions — some dialogs record incompletely
Conditional actions (IF A then do B) — recorded macros have no logic
External application interactions
Scrolling — is recorded but rarely needed in playback

Practical Example — Recording a "Clean Pasted Text" Macro

Goal: Remove double paragraph marks and double spaces from pasted text.

  1. Start recording → name: CleanPastedText → assign shortcut: Ctrl+Shift+C → store in: All Documents → OK
  2. Press Ctrl+H to open Find & Replace
  3. Find what: ^p^p → Replace with: ^p → click Replace All → click OK to the confirmation → do NOT close the dialog yet
  4. Clear Find what → type (two spaces) → Replace with: (one space) → Replace All → OK
  5. Close the Find & Replace dialog
  6. Stop Recording
  7. Result: pressing Ctrl+Shift+C now instantly cleans double paragraph marks and double spaces from any document

24.4 Running a Macro — Five Methods

Method 1 — Keyboard Shortcut (Fastest)

If you assigned a shortcut during recording (or afterwards via the Macros dialog → Options): press the key combination → the macro runs instantly.

Method 2 — Quick Access Toolbar Button

If you added the macro to the QAT: click its button in the top-left toolbar. Hover over the button to see the macro name and description as a tooltip.

Method 3 — Developer Tab → Macros Dialog

  1. Developer → Code group → Macros — or — press Alt+F8
  2. The Macros dialog opens listing all available macros
  3. Select the macro from the list
  4. Click Run

Method 4 — View Tab → Macros

  1. View → Macros group → MacrosView Macros
  2. Same Macros dialog opens → select → Run

Method 5 — Custom Ribbon Button

  1. File → Options → Customize Ribbon
  2. In the right-hand pane, select or create a custom tab/group where the macro button should live
  3. In the "Choose commands from" dropdown → select Macros
  4. Find your macro in the left list → click Add >>
  5. Click the macro in the right list → click Rename to give it a display name and choose an icon
  6. Click OK — the macro button appears in the Ribbon

Running a Macro on a Specific Part of the Document

  • If the macro uses relative cursor positions (operates from wherever the cursor is): place the cursor at the correct location before running
  • If the macro uses absolute selections (Ctrl+A, Ctrl+Home): it always operates on the whole document or from the start, regardless of cursor position

24.5 Managing Macros — Edit, Delete, Rename & Copy

The Macros Dialog (Alt+F8)

The central hub for macro management. Press Alt+F8 — or — Developer → Code → Macros. The dialog shows:

  • A list of all available macros (filtered by the "Macros in" dropdown — change to "All active templates and documents" to see everything)
  • Run — execute the selected macro
  • Edit — opens the VBA Editor (Alt+F11) with the macro code visible for editing
  • Create — opens the VBA Editor to write a new macro from scratch
  • Delete — permanently deletes the selected macro
  • Organizer… — opens the Organizer dialog to copy macros between templates/documents
  • Step Into — runs the macro one line at a time for debugging (pauses after each line in the VBA Editor)
  • Options… — change the macro's keyboard shortcut and description

Renaming a Macro

Word does not have a direct "Rename" button in the Macros dialog. To rename a macro:

  1. Alt+F8 → select the macro → click Edit → the VBA Editor opens showing the code
  2. In the code, change the text after Sub to the new name: e.g., change Sub CleanText() to Sub CleanPastedText()
  3. Press Ctrl+S to save — close the VBA Editor → the macro now appears with its new name

Deleting a Macro

  1. Alt+F8 → select the macro → click Delete → confirm
  2. The macro is permanently removed from the storage location (Normal.dotm or the document)

Copying a Macro to Another Document or Template

  1. Alt+F8 → click Organizer…
  2. The Organizer opens on the Macro Project Items tab
  3. The left panel shows the current document's macro modules; the right panel shows Normal.dotm (or another file)
  4. To change either panel's source: click Close FileOpen File → browse to the target .dotm or .docm
  5. Select the macro module in the source panel → click Copy >> to send it to the destination
  6. Click Close

Changing a Macro's Keyboard Shortcut

  1. Alt+F8 → select the macro → click Options…
  2. In the Macro Options dialog: click in the shortcut key field → press the new key combination → click OK
  3. — or — File → Options → Customize Ribbon → Keyboard Shortcuts: Customize → Category: Macros → find the macro → assign a new key

24.6 The VBA Editor — Reading & Making Small Edits

Every recorded macro produces VBA code. You do not need to become a programmer to make useful edits — understanding the structure of recorded code allows you to tweak, fix, and improve macros without re-recording from scratch.

Opening the VBA Editor

  • Keyboard shortcut: Alt+F11 — opens the VBA Editor directly
  • Developer → Code group → Visual Basic
  • Alt+F8 → select macro → Edit

VBA Editor Layout

VBA Editor Window Layout:

┌─────────────────┬───────────────────────────────────────────────┐
│ Project Explorer│ Code Window (main editing area)            │
│ (left panel)    │                                                │
│ ▸ Normal        │ Sub CleanPastedText()                        │
│   ▸ Modules     │     Selection.Find.ClearFormatting             │
│     Module1     │     ... (more recorded code)                  │
│ ▸ Document      │ End Sub                                      │
│   ▸ ThisDocument│                                                │
├─────────────────│                                                │
│ Properties Pane │                                                │
└─────────────────┴───────────────────────────────────────────────┘

Project Explorer

  • Shows all open documents and templates as a tree structure
  • Each project (document or template) contains folders: Microsoft Word Objects (ThisDocument), Modules (where recorded macros live), Forms (UserForms), Class Modules
  • Double-click any module to open its code in the Code Window

Reading a Recorded Macro

Here is a real example of a recorded macro that applies Heading 1 style and sets font colour to navy:

Sub ApplyCorpHeading1()
'
' ApplyCorpHeading1 Macro
' Applies Heading 1 style with corporate navy colour
'
    Selection.Style = ActiveDocument.Styles("Heading 1")
    With Selection.Font
        .Color = 1709073 ' Navy blue RGB colour value
        .Bold = True
        .Size = 14
    End With
End Sub

Key VBA Code Elements to Recognise

ElementWhat It Means
Sub MacroName()The start of the macro — "Sub" means subroutine (a block of code that runs when called)
End SubThe end of the macro — Word stops executing code here
SelectionRefers to whatever text is currently selected — or the cursor position if nothing is selected
ActiveDocumentRefers to the currently active (foreground) Word document
' Comment textA comment — green text that is ignored during execution. Use comments to explain what your code does.
With ... End WithGroups multiple property settings for the same object — avoids repeating the object name on every line
.Text = "hello"Sets the Text property of the object to "hello" — the text between double quotes is literal text
= True / = FalseBoolean values — True turns a feature on; False turns it off (e.g., .Bold = True, .Italic = False)

Making Small Edits to Recorded Code

Common small edits you can safely make without VBA expertise:

  • Change a style name: Find "Heading 1" in the code → change to "Heading 2" or any valid style name
  • Change a Find & Replace string: Find .Text = "^p^p" → change the text between quotes
  • Change a font size: Find .Size = 14 → change the number
  • Change text to insert: Find Selection.TypeText Text:="your text here" → change the text between quotes
  • Add a comment: Type ' at the start of any line to turn it into a comment (disabling that step)
  • Remove a step: Delete the line(s) that perform the unwanted action — or comment them out with '

Running a Macro from the VBA Editor

  1. Place the cursor anywhere inside the Sub...End Sub block of the macro
  2. Press F5 — or — click the Play button (▶) in the toolbar — the macro runs against the active Word document
  3. Press F8 to step through the macro one line at a time for debugging — each press executes the next line

24.7 Practical Macro Library — Ready-to-Use Examples

These macros can be entered directly into the VBA Editor (Alt+F11 → insert a Module → paste the code). They are simple enough to read and modify without deep VBA knowledge. Each can be recorded with the recorder or typed directly.

Macro 1 — Clean Up Pasted Text

Sub CleanPastedText()
' Removes double paragraph marks and double spaces
    With Selection.Find
        .ClearFormatting
        .Text = "^p^p"
        .Replacement.Text = "^p"
        .Execute Replace:=wdReplaceAll
    End With
    With Selection.Find
        .Text = " " ' two spaces
        .Replacement.Text = " " ' one space
        .Execute Replace:=wdReplaceAll
    End With
End Sub

Macro 2 — Update All Fields & TOC

Sub UpdateAllFieldsAndTOC()
' Updates all fields including tables of contents
    Dim oTOC As TableOfContents
    ActiveDocument.Fields.Update
    For Each oTOC In ActiveDocument.TablesOfContents
        oTOC.Update
    Next oTOC
    MsgBox "All fields and TOC updated successfully.", vbInformation
End Sub

Macro 3 — Insert POPIA Notice

Sub InsertPOPIANotice()
' Inserts the standard POPIA disclaimer at the cursor position
    Selection.TypeText Text:="POPIA NOTICE: The personal information contained in this " & _
        "communication is confidential and intended for the addressee only. " & _
        "If you are not the intended recipient, please notify the sender " & _
        "immediately and destroy this communication."
End Sub

Macro 4 — Apply Landscape A4 Setup

Sub SetLandscapeA4()
' Sets current section to Landscape A4 with 2cm margins
    With ActiveDocument.PageSetup
        .Orientation = wdOrientLandscape
        .PaperSize = wdPaperA4
        .TopMargin = CentimetersToPoints(2)
        .BottomMargin = CentimetersToPoints(2)
        .LeftMargin = CentimetersToPoints(2)
        .RightMargin = CentimetersToPoints(2)
    End With
End Sub

Macro 5 — Word Count Report

Sub ShowWordCountReport()
' Displays word count, page count, and character count
    Dim msg As String
    msg = "Document Statistics:" & vbNewLine & vbNewLine
    msg = msg & "Pages: " & ActiveDocument.ComputeStatistics(wdStatisticPages) & vbNewLine
    msg = msg & "Words: " & ActiveDocument.ComputeStatistics(wdStatisticWords) & vbNewLine
    msg = msg & "Characters: " & ActiveDocument.ComputeStatistics(wdStatisticCharactersWithSpaces)
    MsgBox msg, vbInformation, "Word Count Report"
End Sub

24.8 Saving & Distributing Macro-Enabled Files

File Format Requirements

FormatExtensionCan Store Macros?Use
Word Macro-Enabled Document.docm✅ YesDocuments with embedded macros — shared with others who need to run the macros
Word Document.docx❌ NoStandard documents — if you try to save a .docx with macros, Word strips the macros and warns you
Word Macro-Enabled Template.dotm✅ YesTemplates with macros — the macros run in every document based on the template
Normal.dotm.dotm✅ YesMacros available in all documents — only on the local computer

When Recipients Open a .docm File

With "Disable all macros with notification" security setting (recommended), when a recipient opens a .docm file:

  1. A yellow Security Warning bar appears below the Ribbon: "Macros have been disabled. Enable Content"
  2. The recipient clicks Enable Content to allow the macros to run
  3. Alternatively, if the file is in a Trusted Location, it opens without the warning
Distributing Macro Files Safely: When sending a .docm file externally, always inform the recipient via a separate channel that the file contains a safe macro, what the macro does, and that they should click "Enable Content". Recipients who receive unexpected .docm files from unknown senders should never enable content — it is a standard security precaution.

24.9 Quick Self-Check

Q1: You record a macro that applies a custom style, inserts a table, and types a heading — but when you play it back, the cursor moves to a different position than expected and the text is inserted in the wrong place. What is the most likely recording mistake and how do you fix it?

✓ The cursor was positioned using mouse clicks during recording — the recorder captured the absolute cursor position at recording time, which doesn't match playback context. Fix: re-record the macro and position the cursor exclusively with keyboard shortcuts (Home to go to line start, Ctrl+Home for document start, Ctrl+End for document end, arrow keys for navigation). If the macro should always operate on selected text, ensure the user selects the text before running the macro, and the macro uses Selection.xxx to act on whatever is selected rather than assuming a fixed cursor position.

Q2: You have recorded a very useful macro and want it available to you in every Word document you ever open on this computer. Where should you store it, and how does storing it there affect other users who log into the same computer?

✓ Store it in Normal.dotm (choose "All Documents (Normal.dotm)" during recording). The macro will be available in every document you open on this computer, in every session. However, Normal.dotm is per-user — it is stored in your Windows profile's AppData folder. Other users who log into the same computer with different Windows accounts have their own separate Normal.dotm and will not see your macro. If you want to share the macro with others, copy it to a shared .dotm template that everyone loads, or export the module via the Organizer and share the .dotm file.

Q3: You open the VBA Editor and see this code. Explain what it does in plain English: Selection.Font.Bold = True and Selection.Font.Size = 14

✓ These two lines act on whatever text is currently selected (or the cursor position if nothing is selected). The first line turns on Bold formatting — equivalent to pressing Ctrl+B. The second line changes the font size to 14 points — equivalent to typing 14 in the font size box on the Home tab. Together they make the selected text bold and 14pt. If these lines are inside a Sub...End Sub block, this is a macro that formats selected text with one click.

Q4: A colleague emails you a .dotm file containing a useful macro library. You want to add three of the macros to your own Normal.dotm so they are available in all your documents. How do you do this without copying the entire module?

✓ There are two approaches. Method 1 — Organizer: Alt+F8 → Organizer → close the right panel → Open File → browse to the colleague's .dotm → in the left panel select the module containing the macros → Copy to Normal.dotm on the right → Close. This copies the entire module. Method 2 — Manual copy in VBA Editor: Alt+F11 → open both the colleague's .dotm and Normal.dotm in the VBA Editor → navigate to the module in the colleague's file → select and copy just the three Sub...End Sub blocks → navigate to a module in Normal.dotm → paste. Save Normal.dotm with Ctrl+S. Both methods result in the macros being available in all your documents.

Q5: You want to run your macro on a .docx file, but when you try to save the document containing the macro, Word warns that the macro will be removed. Why does this happen and what should you do?

✓ The .docx format does not support macros — it is a "macro-free" format by design for security. Word strips macros from any file saved as .docx. Solutions: (1) Save the file as .docm (Word Macro-Enabled Document) instead — this preserves the macro in the file. (2) Store the macro in Normal.dotm instead of the document — it then runs from Normal.dotm without needing to be saved in the .docx file. Option 2 is usually preferable for utility macros that apply to many documents rather than one specific file.

Q6: What macro security setting should you use for everyday office work, and why? What would happen if you set it to "Enable all macros"?

✓ Use "Disable all macros with notification" — this blocks macros in files from unknown sources (showing a yellow security bar asking you to decide), while your own macros in Normal.dotm and Trusted Locations run without interruption. It gives you control without being overly restrictive. Setting "Enable all macros" would run every macro in every file automatically — including macros in documents received from email, downloaded from the internet, or shared via USB. Macro malware (macro viruses) embedded in Word or Excel files from external sources would execute automatically without any warning, potentially stealing data, encrypting files, or installing ransomware. Never use "Enable all macros" as a permanent setting.

✓ Module 24 Complete — You Have Learned:

  • What macros are — VBA Sub procedures generated by the recorder; the macro sweet spot (5 task categories); what macros cannot do well
  • Macro security — the four security levels with recommendations; Trusted Locations setup; why "Enable all macros" is dangerous
  • Developer tab requirement for macro work
  • Recording a macro — planning checklist (4 pre-recording considerations); full Record Macro dialog settings (name, assign to Button/Keyboard, store in, description); starting and stopping recording (3 methods each)
  • What the recorder captures vs its limitations (mouse-drag selection, mouse-click positioning, conditional logic)
  • Practical recording example — CleanPastedText step by step
  • Running a macro — 5 methods (keyboard shortcut, QAT button, Alt+F8 dialog, View → Macros, custom Ribbon button)
  • The Macros dialog (Alt+F8) — all 7 buttons (Run, Edit, Create, Delete, Organizer, Step Into, Options)
  • Renaming macros — via VBA Editor Sub name change
  • Deleting macros via the Macros dialog
  • Copying macros between documents using the Organizer
  • Changing keyboard shortcuts via Macro Options
  • VBA Editor layout — Project Explorer, Code Window, Properties Pane; navigating modules
  • Reading recorded VBA code — Sub/End Sub, Selection, ActiveDocument, comments, With/End With, .Text, True/False
  • Small code edits — changing style names, find/replace strings, font sizes, inserted text, commenting out lines
  • Running/stepping through macros in the VBA Editor (F5, F8)
  • 5 practical ready-to-use macros — CleanPastedText, UpdateAllFieldsAndTOC, InsertPOPIANotice, SetLandscapeA4, ShowWordCountReport
  • File format requirements — .docm (macro-enabled document), .dotm (macro-enabled template), .docx (no macros)
  • Distributing .docm files — the Enable Content security prompt and recipient communication

← Back to All Modules