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 currently 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 CreateObject or GetObject functions 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 New keyword 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 New keyword when declaring the Outlook Application object, and then set the variable to Nothing at 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.

FIGURE 8.16

Outlook Explorer and Inspector objects.

FIGURE 8.16

Outlook Explorer and Inspector objects.

The NameSpace, Explorer, and Inspector objects, in addition to the Application object itself, are the key to most of the Outlook components you need to work with, such as folders and items. To work with a folder, for example, you must first set a reference to the Outlook Application object, then the NameSpace object, and then you can retrieve one of the default local folders using the GetDefaultFolder method, or a custom folder by referencing it as a member of the top-level Folders collection, or some folder underneath that folder. (Note that the singular of Folders is now Folder — apparently Microsoft realized that the previous name of MAPIFolder was causing confusion.)

Although the MAPIFolder object has been replaced with the more intuitive Folder object in the Object Browser, you can still declare a folder object as MAPIFolder without causing a compile error. This means you don't need to go through all your old Outlook code and change MAPIFolder declarations to Folder.

0 0

Post a comment