Run Word Document Open Code from an Access VBA Project
Question details
Run Word automation code when documents created by an Access application open, without adding VBA to each document.

- Product
- Microsoft Word and Microsoft Access VBA
- Device & OS
- not provided
- Scenario
- An Access application creates or opens Word documents that need shared open-time behavior.
- Observed behavior
- The user confirmed that code in Normal.dotm works and wants the behavior without embedding a macro in each document.
Identify the Word documents that need the behavior and where their attached template will be stored. Make sure Word is configured to trust the template or its location under your organization's macro security policy.
Put the AutoOpen macro in a custom Word template
Use a shared macro-enabled template to provide open-time behavior without putting VBA in every document.
AutoOpen runs when a document based on the template is opened normally in Word. A custom template limits the behavior to documents that use it; Normal.dotm can affect other Word documents.
If Access opens a document programmatically, explicitly call RunAutoMacros after opening it. The macro itself remains in the Word template, not the Access project.
In Word, create a template and use File > Save As to save it as a Word Macro-Enabled Template (*.dotm). Store it in a location that the intended Word users can access and trust.
Press Alt+F11 in Word, select the template in the VBA editor, and choose Insert > Module. Add a public macro named AutoOpen, such as: Public Sub AutoOpen(): MsgBox "Document opened": End Sub. Replace the message with the required code, then save the template.
In Access, create new Word documents using Documents.Add with the Template argument set to the custom .dotm path. For existing documents, attach the custom template in Word using the Templates and Add-ins dialog, then save each document. The documents can remain .docx files because the macro is stored in the template.
After Access opens an attached document with Word's Documents.Open method, call doc.RunAutoMacros 1 on the returned Word document object; 1 represents wdAutoOpen. For example: Set doc = wdApp.Documents.Open("C:\Docs\Example.docx"): doc.RunAutoMacros 1. Here, wdApp is an existing Word Application object.

Open and edit Word documents with WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Office documents. Its format compatibility makes it easy to move everyday files between suites, but it does not fix Microsoft Access-to-Word VBA automation.

Frequently Asked Questions
Do I need to save every document as a .docm file?
No. Documents can remain .docx files when the VBA code is stored in their attached .dotm template rather than in the documents themselves.
Why use a custom template instead of Normal.dotm?
Normal.dotm is Word's global default template, so code placed there can affect other documents. Attach a custom .dotm template to the documents that need the behavior instead.
Why does AutoOpen not run when Access opens the document?
A document opened programmatically requires an explicit call to its RunAutoMacros method. After Documents.Open returns the document object, call doc.RunAutoMacros 1 to run AutoOpen.
Can this work for documents that already exist?
Yes. Attach the custom template to each existing document through Word's Templates and Add-ins dialog and save it. The template must remain available and trusted when the document is opened.
What should I check if the template macro is blocked?
Check Word's macro security settings and whether the template or its location is trusted under your organization's policy. Confirm that the attached template path is accessible before opening the document.




