The Outlook Object Model
To accomplish a task in Outlook VBA, you use the Outlook object model, a hierarchy of related objects that you use to retrieve information, create new items, and cause Outlook to perform actions. Figure 18-1 shows the object model.

Figure 18-1. The Outlook Object Model—collections are followed by the data types of their contained objects in parentheses
The object model is obviously large and deep, and it’s not our intent to cover the whole thing here. But you can get a good feeling for how to control Outlook by examining some of its major objects: Application, NameSpace, MAPIFolder, Explorer, and Inspector. (For full details on all the objects and their methods and properties, consult the Outlook VBA help available through the VBA editor.) Before we get into the specifics of these objects, we should take a look at a feature common to many of them—events.
Events
Certain
objects in Outlook’s object model can
respond to events. Events are external actions
on an object to which the object can react. For example, the
Application object can react to new mail being received through the
NewMail event. You react to this event by writing
an event handler, or a routine that executes
when the event occurs:
Private Sub Application_NewMail( )
MsgBox "You have new mail!"
End SubThe name of an event handler has the form
Object_Event. In this example, the event handler will ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access