Microsoft Outlook provides a wide range of events through which it can notify your Microsoft Visual Basic, Microsoft Visual Basic for Applications (VBA), and Microsoft Visual Basic Scripting Edition (VBScript) programs that a significant change has occurred.
For example, Outlook events can notify a program when an item has been opened or when a new mail arrives in the InBox.
To receive notification of a significant event, write an event-handler procedure.
Depending on whether the event is handled in Visual Basic or Visual Basic for Applications or in VBScript, this is either a Sub or a Function that Outlook calls when the event is called.
The code you put in the event handler allows your program to respond appropriately to the event and, in some cases, even lets your program cancel the default action associated with the event, such as preventing a mail item from being sent.
Types of Events
Outlook events can be divided into two main categories: item-level events and application-level events.
Application-level events are typically handled by Visual Basic or Visual Basic for Applications because they pertain to more than the items associated with a particular form. Application-level events can pertain to the application itself, to explorer collections and windows (including the Shortcuts pane), inspector collections and windows, folders and folders collections, items collections, and synchronization objects.
Item-level events pertain to a particular item, and are typically handled by VBScript code contained within the form associated with the item. These events notify your program when an item has been opened, sent or posted, saved, or closed, and when the user has replied to or forwarded a message or initiated a custom action. Item-level events can also notify your program when the user has clicked a control on the form or when an item property has changed.
Responding to Events
To respond to item-level events, add event-handler procedures to the script of the form that displays the item. For example, to run code when an item is opened in the form, add a procedure like the following to the script in the form.
MsgBox "A new item has opened in this form."
Responding to application-level events is somewhat more involved because steps must be taken to associate the event handler with the part of Outlook in which the event is occurring. Learn about writing an application-level event handler .
Other Important Events
These include events that are raised on the Application object and events raised on the two main Outlook windows
There are two important windows in Outlook
Explorer - represents the main Outlook application window
Inspector - represents the window that appears when you double click on an individual Outlook item.
You can have zero or more explorers and zero or more inspectors open at any time.
For example you can select "Send to mail recipient" from Excel and an email inspector window will open.
Methods and Events with the same Name
The application, explorer, inspector and item event handlers have increased with every new version which has created some interfaces with the same methods.
If you are adding event handlers dynamically using the AddHandler statement you will have to use the CType operator to cast the Application object to the correct interface.
If you are handlying events declaratively using With Events and Handles you don't have to do this.
For Outlook 2003 development the only interface you need to use is the ApplicationEvents_11_Events.
© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext