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.

The Outlook Object Model—collections are followed by the data types of their contained objects in parentheses

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 Sub

The name of an event handler has the form Object_Event. In this example, the event handler will ...

Get Outlook 2000 in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.