Resume Next
Else
MsgBox “Error No: “ & Err.Number _
& “; Description: “ & Err.Description
Resume ErrorHandlerExit
End If
Referencing Outlook Items in VBA Code ................................................................
Microsoft has chosen to use the same word (for example, Note) to reference different item types
(a mail message’s message class and a Note item in the interface), and to give items confusingly dif-
ferent names in code than they have in the user interface (for example, a Journal item has a message
class of “Activity”). Table 8.1 will help you find the right name or named constant for each situation.
TABLE 8.1
Referencing Outlook Items
Interface Object Model Message OlObjectClass OlItemType
Name Name Class Constant Constant
Contact ContactItem IPM.Contact olContact olContactItem
Task TaskItem IPM.Task olTask olTaskItem
Mail Message MailItem IPM.Note olMail olMailItem
Appointment AppointmentItem IPM.Appointment olAppointment olAppointmentItem
Journal Entry JournalItem IPM.Activity olJournal olJournalItem
Note NoteItem IPM.StickyNote olNote olNoteItem
The message class can be used to create an item of a specific type, or to determine what type of
object you are dealing with (for example, in the active Inspector). It can also be seen in the
“Publish Form As” dialog box when publishing an Outlook item to a library or folder, as shown in
Figure 8.20.
The message class of a custom form consists of the form name appended to the standard object’s
message class, with a separating period. The OlObjectClassnamed constants are used to deter-
mine what type of item you are dealing with, using the Classproperty of an object, whereas the
OlItemTypenamed constants are used for setting or determining the default item type of a
folder, using a Folder’s DefaultItemTypeproperty. See the sample procedures in the next sec-
tions for examples that use these constants.
Part II Writing VBA Code to Exchange Data between Office Components