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.
- Skill level:
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()
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:
.Selection.TypeText Text:="This text was added to a new Word document from Access." .Selection.TypeParagraph
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for