Datasheet
666
Using Object Libraries
Automation with other Microsoft Office programs works only when you have
these programs installed on your computer. If you don’t have Word, Excel,
or Outlook installed, you won’t be able to control them from Access.
Using Object Libraries
To use VBA to control another program, you need to have access to that
program’s object library. Each program has its own set of properties and
methods, which allows VBA to control it. Just as each object (forms, text
boxes, buttons) has its own properties and methods, each application —
including Access — has a set of properties and methods, which is referred to
as the object library.
In order to access another program’s object library, you first have to tell
VBA where to find it. To add an object library to your VBA project, choose
Tools➪References from the Visual Basic Editor menu, and add the desired
object libraries, as shown in Figure 1-1.
Figure 1-1:
Choose
the object
libraries
from the
References
window.
For this example, we added the Microsoft Excel 14.0 Object Library,
Microsoft Office 14.0 Object Library, Microsoft Outlook 14.0 Object Library,
Microsoft Words 14.0 Object Library, and Microsoft PowerPoint 14.0 Object
Library.
If you have multiple versions of a program installed on your computer (for
instance, Excel 2003 and Excel 2010), you’ll see different versions of the
Excel Object Library in the References window. If you’re sure you’ll be work-
ing in the latest version only, choose the version with the highest number.
Applications in Office 2010 are version 14.0, whereas applications in Office
2007 are version 12.0. I guess the superstitious programmers at Microsoft
skipped version 13.0.
44_532188-bk09ch01.indd 66644_532188-bk09ch01.indd 666 3/29/10 10:59 PM3/29/10 10:59 PM










