The Outlook Object Model ..............................................................................................
Because of the limited options for exporting Access data to Outlook, I prefer to use VBA
Automation code to export Access data to Outlook objects. To export Access data to Outlook, you
need to understand the Outlook object model.
The Outlook 2007 object model has a number of new components; they are listed in the MSDN
article “What’s New for Developers in Microsoft Office Outlook 2007 (Part 1 of 2),” which you can
download from the following link: http://msdn2.microsoft.com/en-us/library/
ms772422.aspx#officeoutlook2007whatsnewdeveloperspart1_enhancements.
The Outlook object model doesn’t represent the Outlook interface as closely as the object models
of other Office components; instead of representing contacts, mail messages, tasks, appointments,
and other familiar Outlook objects directly in the object model, these components must be
accessed indirectly, via the Items collection of a Folder object, using specific named constants to
reference or create the specific item types. Folders are accessed through the curiously named
NameSpaceobject (representing the data stored in Outlook folders), which makes for some very
unintuitive code.
Explorer, Inspector, and other Outlook Objects ......................................................
When working with Outlook objects in VBA code, you will mostly be working with folders and
items; occasionally you may also need to use an Explorer or Inspector object. The Explorer object
represents a folder, as displayed in a pane in the interface; the Inspector object represents an item,
as displayed in a window in the interface. Explorers and Inspectors are used to work with the cur-
rently open item or folder; if you just need to create and save items, you don’t need to use these
objects in your code.
In Figure 8.16, the Outlook Contacts folder is displayed in an Explorer pane, and an Outlook task
item is displayed in an Inspector window.
You can use the CreateObjector GetObjectfunctions with the “Outlook.Application”
argument (with the quotes) to either create a new Outlook instance, or retrieve a reference to the
current Outlook instance, if Outlook is running. With Outlook, using the Newkeyword when
declaring an Outlook Application variable is also a useful method, especially if you want to work
with an instance of Outlook other than the one currently in use in the interface.
If your code makes use of Explorer or Inspector objects, it is generally best to use the Newkeyword
when declaring the Outlook Application object, and then set the variable to Nothingat the end of
the procedure, because the user may be opening and closing various folders and windows, which
could cause code errors if you are working with the currently running instance of Outlook.
Part II Writing VBA Code to Exchange Data between Office Components