More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

VBScript in Outlook Development

The code behind Microsoft Outlook forms is always written with the Microsoft Visual Basic Scripting Engine, better known as VBScript, a small portable language, which is also used in web pages and standalone scripts.

VBScript does not support the built-in Outlook constants, such as olFolderContact. Only the constants built into VBScript, such as vbYes, are supported. For Outlook constants, you must either make a Const declaration or use the constant's literal value. Look up any constant in the object browser: Press ALt+F11 to open the VBA environment in Outlook, then press F2.

Debugging VBScript

You can use the Microsoft Script Debugger to debug Outlook form scripts. Make sure you install the HTML Source Editing / Web Scripting / Web Debugging component listed under Office Tools when you do a custom setup or add components. One way to force a script to invoke the debugger is to put a Stop statement in the code. You can also open an item using a custom form, choose Tools | Forms | Script Debugger, and then set breakpoints. Custom form script debugging is not available on Windows Vista unless Visual Studio is also installed. 

Advanced VBScript techniques

Scripting Runtime Library

Use the Scripting Runtime Library to access files and folders and perform some other useful coding tasks. You can also use it in VBA code.

  • FileSystemObject Basics -- Details on how to use the FileSystemObject to access files and folders in VBScript
  • Delete older emails with same subject line -- Uses a Dictionary object to hold the subject and sender name. Note that the For Each loop should be changed to a countdown loop. The sample is for VBA, but it uses the Scripting.Dictionary object, from the Scripting Runtime Library.

Regular expressions

Regular expressions provide a way for searching for patterns in text, such as for email addresses. Again, you can use these techniques in VBA, not just VBScript.

For VBA use, in Tools | References, add a reference to the Microsoft VBScript Regular Expressions 5.5 library. You can then use CreateObject("VBScript.RegExp") to return a RegExp object.

Windows Script Host

Windows Script Host (WSH) lets you run Visual Basic (or Java) script directly within Windows. For basics, see:

If you have WSH installed, you can launch any other program (and most files) with VBScript code like this: 

You can also access the Windows registry with WSH, something VBScript cannot do by itself. See:

WMI Scripting

Windows Management Instrumentation is another scriptable interface, especially useful for digging into the registry entries for Outlook mail profiles. These samples provide examples of WMI in action: