How to Create a Word Document from an Access VBA Template Selection
Question details
The user wants to programmatically create a new Word document based on a specific DOTX or DOTM template selected from a combo box using Access VBA.

- Product
- Microsoft Access / Microsoft Word
- Device & OS
- not provided
- Scenario
- Automating document creation in Access by retrieving a template's name and file path from a combo box selection.
- Observed behavior
- A new Word document needs to be generated automatically via VBA automation, ensuring the correct file path and template name are parsed and passed to Word.
If you plan to use early binding for Word automation, ensure you have enabled the Microsoft Word Object Library reference in your Access VBA editor by navigating to Tools > References.
Use Word Automation and the Documents.Add Method
Use VBA to extract the template path and name from the Access combo box, format the path string, and then use Word automation to create the new document.
This method uses the Documents.Add function in Word VBA, passing the concatenated path and template name as the Template argument. It assumes your combo box stores the template name in the first column (index 0) and the path in the second column (index 1).
Open the VBA editor and declare your Word application and document objects, along with string variables for the path and template name: Dim objDoc As Object, Dim strPath As String, Dim strTemplate As String.
Extract the selected values from your combo box. For example, use strPath = Me.cboTemplate.Column(1) for the path and strTemplate = Me.cboTemplate.Column(0) for the file name.
Ensure the folder path string correctly ends with a backslash to prevent invalid path errors. Add a conditional check: If Right(strPath, 1) <> "\" Then strPath = strPath & "\".
Instantiate the Word application and create the document by calling the Add method. Use the code: Set objDoc = objWord.Documents.Add(Template:=strPath & strTemplate).

Looking for a Cost-Effective Office Suite with VBA Support?
If you are working with macros, templates, and document automation, WPS Office provides exceptional compatibility with Microsoft Office formats and robust VBA macro support in its advanced versions. It is a lightweight, highly compatible, and free alternative to Microsoft Office.
- 1. Download and Install: Get WPS Office from the official website and complete the quick installation process.
- 2. Open Your Documents: Launch WPS Writer and seamlessly open your existing .docx, .dotx, or .dotm template files.
- 3. Use Macro Features: Access the Developer tab in WPS Office to manage, edit, and run your VBA macros directly.

Frequently Asked Questions
Why do I get a 'User-defined type not defined' error in Access VBA?
This error typically occurs when using early binding (e.g., Dim objWord As Word.Application) without enabling the Microsoft Word Object Library reference. Go to Tools > References in the VBA editor and check 'Microsoft Word XX.0 Object Library'.
How can I make the newly created Word document visible to the user?
By default, Word may open invisibly in the background when automated via VBA. To make it visible on the screen, add the code 'objWord.Visible = True' right after creating or getting the Word application object.
Can the Documents.Add method use DOTM templates instead of DOTX?
Yes, the Documents.Add method fully supports both DOTX (standard templates) and DOTM (macro-enabled templates). Just ensure your combo box passes the correct file name with the appropriate extension.




