VBA & Macro Problems

How to Create a Word Document from an Access VBA Template Selection

Aamir Naveed AkramAamir Naveed Akram Oct 28, 2026 869 views

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.

How to Create a Word Document from an Access VBA Template Selection
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.
Before you start

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.

Solution 1Recommended

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).

1
Initialize the Variables

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.

2
Retrieve the Path and Template Name

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.

3
Format the File Path

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 & "\".

4
Create the Word Document

Instantiate the Word application and create the document by calling the Add method. Use the code: Set objDoc = objWord.Documents.Add(Template:=strPath & strTemplate).

Use Word Automation and the Documents.Add Method
Word Instance Management: Use GetObject to connect to an existing Word instance if it is already open, or CreateObject("Word.Application") to start a new instance when connecting via late binding.
Free Microsoft Office alternative

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. 1. Download and Install: Get WPS Office from the official website and complete the quick installation process.
  2. 2. Open Your Documents: Launch WPS Writer and seamlessly open your existing .docx, .dotx, or .dotm template files.
  3. 3. Use Macro Features: Access the Developer tab in WPS Office to manage, edit, and run your VBA macros directly.
Fully compatible with Microsoft Word, Excel, and PowerPoint formats (.docx, .xlsx, .pptx)Supports VBA macros for advanced document automation and scriptingLightweight application that runs smoothly on a wide variety of hardwareFamiliar user interface ensuring a seamless transition and zero learning curve
microsoft office alternative - wps office

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.