How to Edit a Macro in the VBA Editor of Word
🔍 WiseChecker

How to Edit a Macro in the VBA Editor of Word

You recorded a macro in Word using the built-in recorder, but the recorded steps do not match what you need. The Macro Recorder creates VBA code based on your clicks and keystrokes, and that code often includes unnecessary selections or fixed values. To change the macro behavior, you must open the Visual Basic for Applications editor and modify the code directly. This article explains the exact steps to locate, open, and edit a macro in the VBA editor, and it covers common code changes users need to make.

Key Takeaways: Editing a Macro in the VBA Editor

  • Alt + F11: Opens the VBA editor directly from Word.
  • Project Explorer pane: Displays all open documents and their macro modules; double-click a module to see its code.
  • View > Macros > Select macro > Edit: Alternative path to open the VBA editor with the selected macro code visible.

What the VBA Editor Does and What You Need Before Editing

The Visual Basic for Applications editor is a separate window inside Word that lets you read, write, and change VBA code. Every macro you record or write manually is stored in a code module inside a document or template. When you record a macro, Word writes VBA instructions that mirror your actions, but the recorder adds extra lines such as Selection.GoTo or Selection.TypeText that slow down the macro and make it fragile. Editing the macro in the VBA editor removes those redundant lines and lets you add logic, loops, and conditionals.

Before you edit a macro, you need to know the macro name and where it is stored. Macros can be saved in the current document, in the Normal.dotm template, or in another global template. You also need basic familiarity with VBA syntax, such as understanding that lines starting with an apostrophe are comments and that Sub marks the start of a procedure. Word does not require any special permissions to open the VBA editor, but if your organization blocks macros via Group Policy, you will not be able to edit or run them.

Steps to Open and Edit a Macro in the VBA Editor

The following steps use the keyboard shortcut Alt + F11 to open the editor. This method works in Word for Microsoft 365, Word 2021, Word 2019, and Word 2016 on Windows 10 and Windows 11. If you prefer the ribbon path, use View > Macros, select the macro, and click Edit.

  1. Open the VBA editor
    Press Alt + F11 on your keyboard. The VBA editor window appears. If you already have a macro recorded, the editor opens with a blank project tree. Do not close Word.
  2. Locate the macro module in the Project Explorer
    Look at the Project Explorer pane on the left side of the VBA editor. If you do not see it, press Ctrl + R to show it. Expand the project that matches your open document. For example, if your document is named Report.docx, expand Project (Report.docx). Then expand the Modules folder. You will see Module1 or a module named after your macro.
  3. Open the module that contains your macro
    Double-click the module name in the Project Explorer. The code window on the right side displays the VBA code. If you recorded a macro named FormatText, you will see a Sub procedure that starts with Sub FormatText() and ends with End Sub.
  4. Edit the macro code
    Click inside the code window and make your changes. Common edits include removing Selection.GoTo lines, replacing fixed font sizes with variables, or adding a loop to process multiple paragraphs. After you finish editing, press Ctrl + S to save the module. The macro is now updated in the document.
  5. Test the macro from Word
    Switch back to Word by pressing Alt + F11 again or clicking the Word window. Run the macro using View > Macros, select the macro name, and click Run. Check that the result matches your edited code. If the macro fails, return to the VBA editor and verify the syntax.

Editing a Macro Stored in the Normal.dotm Template

If you recorded the macro in the Normal.dotm template so it is available in all documents, the module appears under Project (Normal). Expand Project (Normal) > Modules and double-click the module. Changes to Normal.dotm affect every new document that uses that template. Be careful when editing Normal.dotm macros because an error can break macros in all your documents.

Editing a Macro Assigned to a Button or Keyboard Shortcut

If you assigned the macro to a button on the Quick Access Toolbar or to a keyboard shortcut, editing the code does not change the assignment. After you edit the code, the button or shortcut still calls the same macro name. You do not need to reassign the macro unless you change its name.

Common Mistakes When Editing Macros and How to Avoid Them

The VBA Editor Shows a Compile Error When I Try to Run the Macro

A compile error means the VBA code contains a syntax mistake. Common causes include a missing Next for a For loop, a typo in a variable name, or a missing End If. The VBA editor highlights the line with the error. Check that line and the lines immediately before it. Fix the typo or add the missing keyword, then press Ctrl + S and try again.

The Macro Stops Working After I Edit It But No Error Appears

If the macro runs but does nothing, the code likely contains a logic error. For example, you may have changed a loop counter to a value that never matches, or you removed a line that selected the correct range. To debug, add a breakpoint by clicking in the left margin next to a line. Run the macro; it pauses at the breakpoint. Press F8 to step through each line and watch the values in the Immediate window (press Ctrl + G to open it).

I Cannot See the Project Explorer or the Code Window

If the VBA editor opens but shows only a gray area, press Ctrl + R to show the Project Explorer. If the code window is missing, double-click a module in the Project Explorer. If the module list is empty, you have not recorded or created any macros yet. Close the editor, record a macro in Word, then reopen the editor.

VBA Editor Ribbon vs Keyboard Shortcuts: Navigation Differences

Item Ribbon Path (View Tab) Keyboard Shortcut
Open VBA editor View > Macros > View Macros > Select macro > Edit Alt + F11
Show Project Explorer In VBA editor: View > Project Explorer Ctrl + R
Show Immediate window In VBA editor: View > Immediate Window Ctrl + G
Step through code line by line In VBA editor: Debug > Step Into F8
Save module changes In VBA editor: File > Save (document name) Ctrl + S

You can now open the VBA editor, locate any macro module, and modify the VBA code to remove redundant lines or add logic. Practice editing a simple recorded macro by deleting the Selection.GoTo lines and replacing them with direct object references. Use the Immediate window with Ctrl + G to test small code snippets before adding them to your macro.