DISCOVER
×

How to Access VBA to Open a Word Document

Updated July 20, 2017

Knowing how to open a Microsoft Office Word document and add data to it using Microsoft Visual Basic for Applications (VBA) can be useful when you need to export data from Access. Word is a word processing application included in the Microsoft Office suite. Access is a database management system that is mainly used for smaller databases. VBA is a programming language developed by Microsoft used to automate manual processes. It just takes a few steps to learn how you can create a new Word document and open it using VBA.

Start Microsoft Office Access 2007. Click "Blank Database" and "Create." Select "Database Tools" then click "Visual Basic." Click the "Insert" menu and select "Module."

Click the "Tools" menu then select "References." Check the box next to "Microsoft Word 12.0 Object Library" and select "OK."

Type the following to create a new subroutine:

Private Sub openWordDocument()

Press "Enter."

Type the following to create two new Word variables:

Dim wrdApp As Word.Application

Dim wrdDc As Word.Document

Type the following to define your variables and to add a new document:

Set wrdApp = CreateObject("Word.Application")

wrdApp.Visible = True

Set wrdDc = wrdApp.Documents.Add

Type the following to add new text to the Word document:

With wrdApp

End With

Cite this Article A tool to create a citation to reference this article Cite this Article

About the Author

Jaime Avelar is a professional writer whose programming articles appear on various websites. He has been a software programmer since 2000. Avelar holds a Master of Science in information systems from the University of Texas at Arlington.