Understanding VBA in Outlook

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Developers have wanted to use Microsoft® Visual Basic® for Applications (VBA) in Microsoft® Outlook® since Outlook was first released. Outlook supports both the VBA language and the Visual Basic Editor found in all other Office applications.

Outlook supports a single VBA project that is associated with a particular user and a running instance of the application. The other Microsoft® Office XP applications (except Microsoft® FrontPage®) let you associate a VBA project as code behind an individual Office document. Because Outlook has no document similar to the other Office applications, VBA code is associated only with the application.

Note   The closest thing to a "document" in Outlook is an Outlook item (for example, a mail message, an appointment item, or a task). As in previous versions of Outlook, you use Visual Basic Scripting Edition (VBScript) to write code behind an Outlook item.

The Outlook VBA project is stored in a file named VbaProject.OTM in the following locations:

  • Microsoft Windows.   If user profiles have been set up for multiple users, VbaProject.OTM is stored in the C:\Windows\Profiles\UserName\Application Data\Microsoft\Outlook subfolder. If user profiles have not been set up, VbaProject.OTM is stored in the C:\Windows\Application Data\Microsoft\Outlook subfolder.
  • Microsoft Windows NT Workstation and Microsoft Windows NT Server.   The VbaProject.OTM file is stored in the C:\Winnt\Profiles\UserName\Application Data\Microsoft\Outlook subfolder.
  • Microsoft Windows 2000.   The VbaProject.OTM file is stored in the C:\Documents and Settings\UserName\Application Data\Microsoft\Outlook subfolder.

You use VBA in Outlook to customize the application by working with the objects, methods, properties, and events available through the Outlook object model. For example, you can add code to application-level events to process messages, add custom command bar controls to call custom VBA procedures, or create Component Object Model (COM) add-ins by using the Visual Basic Editor to debug the add-in as it is being developed and tested. You can access the Visual Basic Editor just as you do in any other Office application, by pointing to Macro on the Tools menu, and then clicking Visual Basic Editor.

See Also

Working with Microsoft Outlook Objects | Understanding the Application and NameSpace Objects | Working with Outlook Folders and Items | Understanding the Explorer and Inspector Objects | Understanding Events in Outlook | Add-ins, Templates, Wizards, and Libraries