Chapter 4. Outlook VBA

In this chapter, you learn more about working with the Outlook VBA project, and how to use it to create macros and to prototype code destined for use in COM addins and standalone projects.

The code in this chapter uses the intrinsic ThisOutlookSession class module, custom classes, and VBA UserForms for user input and data display to create macros that you can run on demand as well as code that runs automatically when Outlook starts or in response to specific Outlook events. These types of uses are common not only for VBA macro code but also in almost every Outlook application you write, including COM addins and standalone projects.

The Outlook VBA Project

Unlike Office applications such as Word, where the VBA project is document oriented, Outlook code is oriented towards the application. This orientation is similar to the orientation of COM addins and standalone projects, and makes Outlook VBA especially useful as a prototyping tool. The VBA project is also used for creating two classes of macros, macros that run automatically and those that are run on demand by the user, which you learn about in this chapter.

The Project File

Outlook has one global VBA project file, stored in the file system as VBAProject.OTM. This file is usually located in the C:\Documents and Settings\<windows logon>\Application Data\Microsoft\Outlook folder, where <windows logon> is the current user logon name for Windows. All Outlook VBA code is contained in this project file. This is unlike ...

Get Professional Outlook® 2007 Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.