How to Create Basic Macros in Word

By Alex March 15, 2026 word-tutorial

Understanding Word Macros

Macros automate repetitive tasks by recording a sequence of actions and replaying them with a single command. A simple macro might format text consistently, while complex macros handle multi-step document processing.

Macros save time on frequently repeated tasks and ensure consistency by eliminating manual variation. Even simple macros can significantly improve productivity.

Recording Your First Macro

Starting the Macro Recorder

Go to View > Macros > Record Macro (or Developer > Record Macro). The Record Macro dialog appears.

Name your macro descriptively (like “Format_Heading” or “Insert_Header”) using only letters, numbers, and underscores.

Choose where to store the macro:

  • All Documents (Normal.dotm) - available in all Word documents
  • This Document - available only in current document
  • Build New Template - creates a new template with this macro

For general-use macros, save in All Documents.

Setting a Keyboard Shortcut

In the Record Macro dialog, optionally assign a keyboard shortcut. Click in the “Keyboard” field and press your desired shortcut (like Ctrl+Alt+H).

Word checks if the shortcut is already assigned. Choose a shortcut not in use.

Keyboard shortcuts make macros quick and convenient to use.

Adding a Description

Type a brief description of what your macro does. This helps you remember its purpose later and appears in macro lists.

Good descriptions are clear and specific.

Recording Your Actions

Click OK to start recording. Word begins capturing every action:

  • Keyboard input
  • Mouse clicks
  • Menu selections
  • Formatting changes

A recording indicator appears showing recording is active.

Completing the Recording

Perform the exact sequence of actions you want the macro to repeat. Work carefully—every action is recorded.

When finished, go to View > Macros > Stop Recording to end the recording.

Testing Your Macro

Place your cursor in a new location and test your macro:

  • Use the keyboard shortcut if you assigned one
  • Or go to View > Macros > View Macros > select your macro > Run

Your recorded actions should repeat exactly.

Running Macros

Using Keyboard Shortcuts

If you assigned a keyboard shortcut, press it to run the macro. The recorded actions execute instantly.

Keyboard shortcuts make macros efficient to use repeatedly.

Using the Macro Dialog

Go to View > Macros > View Macros (or Developer > Macros). In the Macros dialog, select your macro and click Run.

The Macro dialog also displays all available macros, helping you choose which to run.

Adding Macros to the Quick Access Toolbar

Add frequently used macros to your Quick Access Toolbar for one-click access.

Right-click the Quick Access Toolbar and select “Customize Quick Access Toolbar”. In Options, select “Macros” from the dropdown, find your macro, and click Add.

Managing Your Macros

Viewing All Macros

Go to View > Macros > View Macros to see all available macros. This dialog shows:

  • Macro names
  • Which document/template they’re stored in
  • Descriptions

Use this view to manage, run, or edit macros.

Editing Existing Macros

In the Macros dialog, select a macro and click Edit. The Visual Basic Editor opens showing the macro’s code.

The code displays what actions the macro performs. Experienced users can modify code to enhance macros.

Deleting Unwanted Macros

Select the macro in the Macros dialog and click Delete. Confirm deletion.

This removes the macro code and frees up storage space.

Renaming Macros

Select a macro in the Macros dialog and click Edit. In the Visual Basic Editor, find the Sub line with the macro name. Change the name carefully—it must follow naming rules (no spaces, special characters).

Editing Macros with VBA

Understanding Visual Basic for Applications

Visual Basic for Applications (VBA) is the programming language Word uses for macros. Basic VBA knowledge allows customizing macro behavior beyond recording.

Common VBA concepts for beginners:

  • Sub (macro definition)
  • With…End With (work with document objects)
  • Selection (active text)
  • Range (specific document area)

Making Simple Code Edits

In the Visual Basic Editor:

  1. Find the macro code (Sub MacroName…End Sub)
  2. Understand what each line does
  3. Make careful edits
  4. Click Save to save changes
  5. Close the editor

Small edits can customize macro behavior without completely rewriting code.

Adding Comments to Your Code

Start lines with apostrophe (’) to add comments explaining code. Comments don’t affect macro function but help you understand code later.

' This macro formats selected text as a heading
With Selection.Font

Good comments make code easier to maintain.

Creating Macros from Scratch

Writing VBA Code

Experienced users can write macros from scratch using the Visual Basic Editor.

Go to View > Macros > Edit Macros, then type new code in the editor:

Sub MyCustomMacro()
  ' Macro code here
  Selection.Font.Bold = True
  Selection.Font.Size = 14
End Sub

This example makes selected text bold and 14pt.

Testing Your Code

After writing code, click Run to test it. If errors occur, error messages help identify problems.

Debug errors by carefully reviewing code logic.

Advanced Macro Techniques

Adding User Input

Macros can prompt for information:

Dim userName As String
userName = InputBox("Enter your name:")
Selection.InsertBefore userName

This macro asks for a name and inserts it into the document.

Conditional Logic

Macros can make decisions:

If Selection.Font.Bold = True Then
  Selection.Font.Bold = False
Else
  Selection.Font.Bold = True
End If

This toggles bold formatting.

Looping Through Content

Macros can process multiple items:

For Each p In ActiveDocument.Paragraphs
  p.Style = "Heading 1"
Next p

This applies Heading 1 style to all paragraphs.

Security Considerations

Macro Security Settings

Go to File > Options > Trust Center > Trust Center Settings > Macro Settings to control macro behavior.

Settings include:

  • Disable all macros
  • Disable with notification
  • Disable all unsigned macros
  • Enable all macros (not recommended)

Choose settings balancing security and convenience.

Signing Macros

Organizations can digitally sign macros to verify authenticity. Signed macros from trusted sources run without prompts.

Signing requires a digital certificate from your IT department.

Distributing Macros

Sharing Macro-Enabled Templates

Save templates with macros as .dotm files (Macro-Enabled Templates). Recipients can use the template and access included macros.

Documenting Your Macros

Provide documentation with macro-containing files:

  • List macro names and shortcuts
  • Explain what each macro does
  • Note any special requirements
  • Provide troubleshooting help

Good documentation helps others use your macros effectively.

Using GenText with Macros

GenText can help by:

  • Generating sample content for macro testing
  • Creating test documents to verify macro functionality
  • Producing content in different formats to test macro robustness

Test macros with various content before distributing to others.

Best Practices for Macro Development

Start with Recording

Begin with recorded macros before attempting to write VBA code. Recording shows how Word represents actions in code.

Test Thoroughly

Test macros on various documents and content types before distributing. Macros might behave differently with different document structures.

Document Your Work

Include clear descriptions in macro names and add comments in code. Future you will appreciate understanding what your macro does.

Keep It Simple

Simple macros are easier to create, test, and modify. Break complex tasks into multiple simpler macros.

Conclusion

Word macros transform repetitive manual tasks into one-click automation. Whether you record simple formatting macros or write VBA code for complex document processing, macros increase productivity and ensure consistency. Start with recorded macros and progress to editing code as your confidence grows.

Frequently Asked Questions

Are Word macros safe to use?

Macros are generally safe when created by trusted sources. Be cautious with macros from unknown sources as they can contain malicious code. Word displays security warnings for unsigned macros.

What's the difference between recording and editing macros?

Recording captures your mouse clicks and keyboard actions automatically. Editing manually writes or modifies macro code using Visual Basic for Applications (VBA).

Where are my created macros saved?

Macros can be saved in the current document (document-specific), in Normal.dotm (available in all documents), or in a specific template.

Related Guides

Spend Less Time Formatting

GenText handles formatting inside Word so you can focus on your writing.

Try Free
word-tutorial microsoft-word macros automation