About the object environment

Microsoft Office Outlook 2003

About the object environment

There are two ways to write code for Outlook:

  • From outside the application, such as by using Microsoft Visual Basic or Microsoft Visual Basic for Applications in Microsoft Excel or another application.
  • From inside the application, such as by using Visual Basic for Applications or by using VBScript with an Outlook form.

Learn more about the differences between using Visual Basic for Applications and VBScript

The major components of the Outlook object model are:

Application The top of the object hierarchy that represents the entire application. Enables you to reference other objects in the application and create items and objects. For example, this code creates an appointment in Outlook Visual Basic for Applications or VBScript:
Application.CreateItem(1).Display
					
NameSpace Represents the MAPI message store where all the Outlook items are stored. Provides methods for logging on and off Outlook and for referencing the default folders such as Mailbox, Inbox, Contacts, and others. For example, this code references the active user in Outlook Visual Basic for Applications or VBScript:
Application.GetNameSpace("MAPI").CurrentUser
					
Explorer Represents the Outlook window. Enables you to show, return, and close the active window. For example, this code shows the active Outlook window in Outlook Visual Basic for Applications or VBScript:
Application.ActiveExplorer.Display
					
Folders There are two folder objects, the Folders collection object that enables you to work with collections of folders and the MAPIFolder object that enables you to work with a single folder. For example, this code shows the collection of folders named Personal Folders in Outlook Visual Basic for Applications or VBScript:
Application.GetNameSpace("MAPI").Folders("Personal Folders")
					
Outlook items There are two item objects, the Items collection object that enables you to work with items within a folder and the item objects that represents the standard item types in Outlook, such as MailItem that represents a mail message. In VBScript, the active item is assumed, so you do not need to enter the object model to reference it. For example, this code sets the Subject field of the active message in VBScript:
Item.Subject = "New Subject"
					
Inspector References forms. Use to show forms and pages. For example, this code shows the Options page of a form in Outlook Visual Basic for Applications or VBScript:
Application.ActiveInspector.SetCurrentFormPage("Options")
					
AddressEntry Each AddressEntry object in the AddressEntries collection holds information that represents a person or process to which the messaging system can deliver messages.
AddressList The AddressList object is an address book that contains a set of AddressEntry objects. The entire hierarchy is available through the parent AddressLists collection.
Exception The Exception object holds information about one instance of an AppointmentItem object which is an exception to a recurring series. Unlike most of the other Outlook objects, the Exception object is a read-only object.
Control There are two control objects, the Controls collection object that enables you to work with all the controls on a page and the specific control object that enables you to work with a control. For example, this code sets the Caption of a CommandButton control named "CommandButton1" on a page named "Test" in VBScript:
Item.GetInspector.ModifiedFormPages("Test").Controls("CommandButton1").Caption = "New Caption"