How to Save Macro to Specific Document Only
🔍 WiseChecker

How to Save Macro to Specific Document Only

You have written a VBA macro in Word that automates a repetitive task, but you need it to run only when a particular document is open. By default, Word stores macros in the Normal.dotm template, which makes them available to all documents. This article explains how to save a macro directly into a single document so it does not affect other files.

The solution is to store the macro in the document itself rather than in a global template. Word supports two storage locations for macros: the document body and the global template. When you save a macro inside a document, that macro travels with the file and runs only when that document is active. This approach is ideal for workflow-specific automation that should not clutter the global environment.

This article covers the exact steps to create a macro in a document, how to verify it is stored correctly, and what to do if the macro does not appear when you reopen the file. You will also learn the differences between document-level and global macros so you can choose the right approach for each project.

Key Takeaways: Saving a Macro to a Single Word Document

  • Developer tab > Code group > Macros > Macro name > Store macro in dropdown > Document name: The only correct way to assign a macro to a specific document instead of the global Normal.dotm template.
  • File > Save As > Word Macro-Enabled Document (docm): The required file format for any document that contains macros. A regular .docx file will discard macro code when saved.
  • File > Options > Trust Center > Trust Center Settings > Macro Settings > Enable all macros: Necessary security setting to allow macros to run in the document. Without this, the macro will not execute.

Understanding Macro Storage Locations in Word

Word stores VBA macros in one of two places. The default location is the Normal.dotm global template. Any macro saved there is available to every document you open. The second location is the document itself. A macro stored in a document is called a document-level macro. It is embedded in the file and runs only when that specific document is active.

The key requirement for document-level macros is the file extension. A standard Word document uses the .docx extension. This format cannot contain VBA code. You must save the file as a Word Macro-Enabled Document with the .docm extension. If you save a .docm file as .docx, Word removes all macros silently. The macro is lost permanently unless you have a backup copy.

Another important factor is the Trust Center security setting. By default, Word disables all macros with notification. You must change this setting to enable macros to run. This setting applies to all documents, not just the one containing your macro. You can adjust it temporarily and revert after testing.

Steps to Save a Macro to a Specific Document

Follow these steps to create a new macro and store it inside a single document. The procedure assumes you have already opened the target document in Word.

  1. Enable the Developer tab
    Go to File > Options > Customize Ribbon. In the right panel under Main Tabs, check the box next to Developer. Click OK. The Developer tab now appears on the ribbon.
  2. Open the Visual Basic Editor
    On the Developer tab, click Visual Basic. Alternatively, press Alt+F11. The VBA editor opens.
  3. Insert a module in the correct project
    In the Project Explorer pane on the left, locate the project that matches your document name. It appears as Project (YourDocumentName). Right-click that project, select Insert, then Module. A new code module appears under the project.
  4. Write or paste the macro code
    In the module window, type or paste your VBA code. For example:
    Sub MyDocumentMacro()
    MsgBox "This macro runs only in this document."
    End Sub
  5. Save the document as a macro-enabled file
    Close the VBA editor. Go to File > Save As. In the Save as type dropdown, select Word Macro-Enabled Document (docm). Choose a folder and file name, then click Save.
  6. Enable macros in the Trust Center
    Go to File > Options > Trust Center > Trust Center Settings. Select Macro Settings. Choose Enable all macros. Click OK twice.
  7. Test the macro
    Press Alt+F8 to open the Macros dialog. In the Macros in dropdown, confirm that your document name appears. Select your macro and click Run. The macro executes.

What to Do If the Macro Does Not Appear After Reopening

If you reopen the document later and the macro is missing or does not run, check these three factors in order.

Did you save as .docm instead of .docx?

The most common cause is saving the file with a .docx extension. Word silently discards all VBA code when you save as .docx. Open the file, check the file extension in the title bar or File Explorer. If it ends in .docx, the macro is gone. You must recreate it and save as .docm.

Is the macro stored in the correct project?

Open the VBA editor with Alt+F11. In the Project Explorer, look for a project named after your document. If the macro is inside Project (Normal) instead, it is a global macro, not a document-level one. Right-click the module in Normal, choose Remove, then re-insert the module under the correct document project and repeat the save steps.

Are macros enabled in Trust Center?

Word disables macros by default when you open a file from an untrusted location. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings. If the setting is Disable all macros without notification, change it to Enable all macros. Also add the folder containing your .docm file to the Trusted Locations list to avoid the security prompt each time.

Word Document Macro vs Global Macro: Key Differences

Item Document-Level Macro Global Macro (Normal.dotm)
Storage location Embedded in the .docm file Normal.dotm template in the user templates folder
Scope Only the host document All documents opened in Word
File extension required .docm None (Normal.dotm is always loaded)
Portability Travels with the document file Stays on the local machine only
Backup risk Lost if saved as .docx Lost if Normal.dotm is corrupted or deleted
Best use case Single-project automation Reusable utilities across all work

You can now save a macro to a specific document and keep your global template clean. Use the Developer tab to insert a module into the correct project, write your code, and save the file as .docm. Always verify the file extension after saving. For security, enable macros in the Trust Center or add the document folder to Trusted Locations. As an advanced tip, you can also export a module from the VBA editor as a .bas file and import it into any document project without retyping the code.