The Outlook object model
Outlook s object model is quite different from those of the other Office applications. That s because it grew up in a different family and was adopted by Office. It s only with Office 2000 that you can use VBA to write macros for Outlook, and there s still no way to record a macro as there is in the other Office products. (This, of course, makes figuring out the syntax for automating Outlook a lot harder. You can t just record a macro and convert the code.)
Because of Outlook s varied history, the examples in this chapter have been tested only with Outlook 2000. They may well work with earlier versions, but we re making no promises on that front.
Like the other Office applications, Help has a live diagram of the object model. Figure 1 shows the main page of the diagram.
As in the rest of Office (and many other servers), there s an Application object at the top that represents the server itself. This is the object you instantiate with CreateObject() we ll look at that in the next section, "Getting a handle on Outlook." As you d expect, it has a Quit method to shut the application down. However, there s no Visible property, no Top and Left properties to indicate where the application is positioned, and no StartupPath property to indicate where data is to be placed.
More striking, though, is that once you have the Application object in hand, there s no object that jumps out at you as clearly the key to the Outlook object model the way Document does in Word or Presentation does in PowerPoint. That s because there is no one dominant object the closest is probably MAPIFolder. Each MAPIFolder represents one of Outlook s folders, so there s a MAPIFolder object for the Calendar, another for Contacts, a third for the Inbox, and so on. MAPIFolder objects are gathered into a Folders collection. To complicate (or is it confuse?) matters, MAPIFolders can be nested. In fact, the Folders collection containing the key Outlook objects is contained in another MAPIFolder object called "Personal Folders." That MAPIFolder is contained in yet another Folders collection, which is contained in a NameSpace object. (Don t worry if this seems complicated. We ll dig into it with examples later on.)
Figure 1
. Outlook object model. Unlike the other Office objects, there s no obvious candidate for the key object below Application.
Copyright 2000 by Tamar E. Granor and Della Martin All Rights Reserved