More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

To distribute Microsoft Outlook VBA code to other users

Outlook VBA code is designed for personal use. It was never intended for distribution to large numbers of users. There is, in fact, no supported way to distribute Outlook macros, as there is with document-centric programs like Word and Excel.

The recommended solution is to build an add-in, either a classic COM add-in for Outlook 2000 or later or an add-in based on the .NET Framework for Outlook 2003 or later with Visual Studio Tools 2005 for Office.

Realistically, though, not every organization that wants to leverage Outlook as an application platform or enhance its functionality has the resources to create add-ins. For those organizations, this page discusses strategies for distributing VBA macros. Note that these techniques are unsupported and that VBA code has been known to simply disappear. Good backups and patience are essential. Your mileage may vary.

Export/Import

The least intrusive technique is to use the File | Export command in the Outlook VBA environment to export modules as .bas, .cls, and .frm files. You can then give these files to other users and tell them how to reverse the process with File | Import. If you export a form, be sure to distribute both the .frm file and the .frx file.

This method has the advantage of preserving any VBA code that the user may have already written. Disadvantages include:

  • It's tedious if you have a lot of modules.
  • If you export the built-in ThisOutlookSession module, then try to import it, the user will get a ThisOutlookSession1 class module, but code in it won't run automatically as it does in ThisOutlookSession. The user will have to cut and paste the procedures from the imported class module into the built-in ThisOutlookSession module.
  • The user will have to resolve any procedure name overlap between existing modules and those imported.
Copy VbaProject.otm

All Outlook macros are stored in a single file named VbaProject.otm in the user's %appdata%\Microsoft\Outlook folder, which will be a hidden folder on most systems. The brute force approach is to copy this file from the machine where the macros were written to other users' machines, replacing any existing VbaProject.otm file. You can do this with whatever technique you normally use in your organization to copy files to users, including walking it around on a disk to each workstation.

This method has the advantage of being a relatively simple process of copying a single file, once you figure out the destination folder. (TIP: You can enter %appdata%\Microsoft\Outlook in Start | Run or the Address box in Windows Explorer to go directly to the right folder.)

Disadvantages include:

  • Any Outlook VBA code the user already has will be lost.
  • In Outlook 2000 and 2002, at least, the user will need to use Alt+F8 or Alt+F11 manually before any Application-level event code will fire.
Office Profile Wizard Method 1

If you want to distribute Outlook VBA macros as part of an initial Office installation in Outlook 2003 or earlier, you can use the Office Profile Wizard from the Office Resource Kit. This tool saves all the settings for one or more applications on a machine where Office is already installed into an .ops file, which can be imported into another ORK tool, the Custom Installation Wizard, for deployment to users. Among the files included would be the VbaProject.otm file.

If you use this method and your VBA procedures include macros that can be run from the Tools | Macros dialog or by pressing Alt+F8, you may also want to go ahead and configure a toolbar button for each macro. Toolbar customizations are stored in a file named Outcmd.dat, which will also be picked up by the Office Profile Wizard.

This method has the same disadvantages as copying VbaProject.otm.

OPW Method 2

You can also use the Office Profile Wizard (Proflwiz.exe) to distribute just the VBA project and, optionally, the Outcmd.dat toolbar customization file, from a current installation by starting the OPW with a customized .ini file. Follow these steps:

  1. Create the .ini file: Copy the text below into Notepad and save the file with the name VBAmacros.ini. (Note that this .ini file is for use with the Office 2003 version of the OPW. Consult the ORK documentation for details on earlier versions.)

  1. On the machine where you have created the Outlook VBA macros, run the OPW with this command line:

"C:\Program Files\Microsoft Office\OFFICE11\Proflwiz.exe" /s "%userprofile%\My Documents\vbamacros.ops" /q

This will create a file named vbamacros.ops in you’re my Documents folder.

  1. Copy the .ops file to a shared network folder if you want other people to be able to use it without having to copy it to their own machine.
  2. Load the .ops file with this command line:

"C:\Program Files\Microsoft Office\OFFICE11\Proflwiz.exe" /r "\\servername\sharename\vbamacros.ops" /q

where \\servername\sharename is the UNC path to the shared folder containing the .ops file. This will copy the Vbaproject.otm and Outcmd.dat files to the correct location on the user's machine, overwriting any previous versions.

Alternatively, instead of Step 4, you can have the user run  the Save My Settings Wizard from the Start menu and browse to the .ops file.

This method has the same disadvantages as copying VbaProject.otm manually. Its chief advantage is that it always copies the file to correct location in the user's Windows profile folders.