Access VBA Macro Programming

(Joao Candeias) #1

Chapter 17 Using Access to Interact with Other Office Programs


Chapter 17 Using Access to Interact with Other Office Programs


A


ll Microsoft Office applications use VBA as their underlying macro language, and
they all have their own object model in the same way that Access has.

Because of this, Access VBA provides an enormous advantage over non-Microsoft
programming languages when it comes to driving other Office programs. For example, you
can create a Word document from within Access without Word ever appearing on screen.
This may sound farfetched, but it is very easy to do. For example, you may design some code
to manipulate data in a database. Your user may require the output to end up in a Word
document or as part of that document. Access gives you the facility to open an external Word
document, enter your data into it, and then save it, without even having any knowledge of
how the file structure works in Word.
This can be done by using theCreateObjectmethod in VBA. In order to useCreateObject,
first add a reference in your application to the appropriate Microsoft Office Object Library
file—in this case, the Word Object Library. If you have Office installed, this file will already
be available and will automatically appear in the References list without your having to
browse for its location. If you do not have all of Microsoft Office installed, you may not have
this library file available unless it has been installed previously as part of another application.
When you add a reference to an Object Library, it then allows you to create objects for
that application and to use the object model of that application, just as if you were
programming in VBA inside that application.


221

Free download pdf