This page has been archived and is no longer  being actively maintained.
Outlook Developer Home
Outlook Programmer's Library
 
Outlook Technologies
Outlook Forms
Languages
Samples
Other Technologies

 

VB and VBA in Outlook Development

For the current version of this page, click here.

Microsoft Outlook forms use VBScript, but you can also control Outlook using Visual Basic itself or using Visual Basic for Applications (VBA) from within an Office application.

Outlook 2000 and later versions support VBA, allowing you to write code to control Outlook and respond to its events. Launch VBA in Outlook by pressing Alt+F11. You will see a built-in ThisOutlookSession module and can add other modules of your own. Argumentless procedures written in Outlook VBA can be launched as macros by pressing Alt+F8 or by adding the macro as a custom toolbar button. However, Outlook 2000 VBA routines cannot be used in earlier versions.

You can also use VB to write .dlls and ActiveX controls that can be used to provide additional functions to Outlook forms. 

The key to using VB with Outlook is understanding the Outlook Object Model. For a quick look at how to use Outlook objects, see HOWTO Automate Outlook using Visual Basic.

VBAProject.otm | Tools | Discussion | Techniques | Tutorials | Samples | Problems | More Information

VBAProject.otm

Any code that you create in the Outlook VBA environment is stored in a file named VBAProject.otm. The location of this file depends on your exact Windows setup; see Outlook & Exchange/Windows Messaging Backup and Dual-Boot.

When you first open Outlook VBA, it will already have a built-in class module named ThisOutlookSession which supports an intrinsic Application object and its events. In addition to backing up the VBAProject.otm file, you might also want periodically to export the individual modules from the project and back them up, too.

You can copy the VBAProject.otm file to another user's machine but the macros won't run until the user has actually used one of the Tools | Macro commands. See Distributing Microsoft Outlook VBA Code for other thoughts and techniques on distributing VBA macros.

Also, in Outlook with the Email Security Update, macro security is set to High by default, which means that unsigned projects will not run at all. You can use the Selfcert.exe program on the Office CD to generate a local security certificate for signing the project. 

Even though you can copy the VBAProject.otm file, it's still not a supported method for distributing Outlook macros company-wide. The recommended method is to create an Outlook COM add-in.

Back to Top

Tools

MAPIProp Free COM component designed to read MAPI-properties of CDO and Outlook Object Model objects for Microsoft Outlook 2000, 2002/XP, 2003 without triggering security prompts. Microsoft Visual C++ 6.0 source code included.
Outlook Plus Events Inexpensive developer library that enhances the events available for the Items and Folders collection to provide  more reliable Add and Change events and Remove events that include the EntryID of the removed item or folder.
Outlook Redemption Provides an interface to Outlook objects that avoids the "object model guard" of the Outlook E-mail Security Update and exposes properties and methods not available through the Outlook model, such as sender address, the RTF body of an item, and Internet message headers. Several security features protect it from being used by malicious programs to send Outlook mail. For the redistributable version, it adds a Profman.dll component with the ability to enumerate, add, delete, and modify Outlook mail profiles using VB or VBScript.
Outlook Spy Developer utility for finding out what's going on inside Outlook, via the Outlook object model, CDO and MAPI. You can edit and delete most properties, drag properties from one item to another, copy values to the clipboard, run scripts, monitor events, browse toolbars to get CommandBars IDs.
Selfcert.exe Tool on the Office 2000 and 2002 CDs for signing VBA projects you create for yourself, so that you do not get a macro prompt when you start Outlook. Once you run it, restart Outlook and in the VBA window, choose Tools | Digital Signature, then click Choose to sign your project with the new certificate:
Back to Top

Discussion

  Back to Top

Techniques

"Object model guard" security prompts
Working with toolbars and menus:

Also see samples under next heading.

Wrapper classes for multiple object event handling

Many Outlook applications require that multiple objects of a particular type be monitored for events, for example, monitoring multiple folders for new items or capturing the Write for all ContactItem objects. The solution is to use a wrapper class. These examples show how:

Drag and drop:
Back to Top

Tutorials

Back to Top

Samples

Basics:
More at Microsoft: 
From other resources:
Back to Top

Problems

For other version-specific issues, including fixes in various service packs, see:
Back to Top

More Information

Outlook 2003:
Outlook 2002:
Outlook 2000:
Outlook 97/98:
   
© 2002-6 TurtleFlock, LLC
All right reserved.
About OutlookCode.com

Send comments to webmaster@outlookcode.com

Designed and Implemented by TerraLink USA 

FrontPage Integration
by RobsonDesignWorks

 
 
get Sue's code | forums | share your own code | registration