Microsoft Office Tutorials and References
In Depth Information
Merging Data with a Word Document
Outlook’s object library exposes many more objects and methods than we
describe here. You can do anything from VBA that you can do from the
Outlook program, such as compose and send e-mail messages, create and
schedule calendar items, and build tasks and to-do lists. To find out more
about these objects, properties, and methods, open the Object Browser, and
choose Outlook from the Project/Library drop-down menu in the top-left
Book IX
Chapter 1
Merging Data with a Word Document
Microsoft Word is probably the most widely used word-processing program
in the world, if not the universe. If you have Microsoft Office installed, you
almost certainly have Word installed as well. Many people in any given work
environment know how to use and edit Word documents, but they may not
know how to create and modify an Access report. Using Automation, you
can enable some users to edit the body of a form letter in Word and then
print that letter from Access. This section shows you how.
To control Word 2013 with VBA, you must first add the Microsoft Office
Word 15.0 Object Library to VBA by using the References dialog box (see
“Working with Object Libraries,” earlier in this chapter).
Creating a Word template
To put data from Access in a Word document, you have to tell Access where
in the Word document to put that data. One method is to create bookmarks in
the Word document; later, Access can replace these bookmarks with data
from the database. A bookmark in Word is just a placeholder. If you do this
in a Word template file (.dotx file), you can easily create new documents
based on this template.
First, use Word to create a new document, and format the document however
you want. You can add a company logo and other letterhead information,
and type the body of the letter. This task should be pretty easy. When you
save the file, choose File Save As to open the Save dialog box, and from the
Save As Type drop-down menu, choose Word Template (*.dotx).
Viewing and inserting bookmarks
When you get the document ready, you need to add bookmarks where you
want the data from Access to go. Bookmarks in Word are usually hidden, so
you need to start by displaying them so that you can see what you’re doing.
Follow these steps:
1. In Microsoft Word, choose File Options.
2. Click the Advanced option on the left side of the Word Options window.
Search JabSto ::

Custom Search