Application Level Customizations Using VSTO

If you have ever customized Outlook by using VBA or by creating a COM add-in, then you know that these customizations are application-level. VSTO supports application-level customization for Outlook through managed add-ins. Because Outlook doesn't have "documents" in the same way that Word and Excel do, it makes sense that the customiza-tions are associated with the entire Outlook application. VSTO provides a type that wraps the Outlook Application object, but it does not add any functionality to the Outlook object model. Instead, VSTO provides a mechanism for loading Outlook add-ins, an add-in project template, a Setup project, and a more stable add-in model.

When you customize Outlook using VBA, your code is added to a VBA project in the Visual Basic Editor. You cannot record macros for Outlook (as you can in Word or Excel); instead, you must write your code directly in a code module in the VBE. You can write your code in the ThisOutlookSession code module, and you can add new code modules to your VBA project.

Using the ThisOutlookSession code module gives you access to a number of application events, where you can create event handlers and write code to handle the events, as shown in Figure 10.1. For example, you might want to write code that is called whenever an e-mail message or meeting request is sent.

Figure 10.1. Outlook application events available in the VBE

Code written in the VBE is available only to the user who created the code, or to users who have imported the code file into their VBA projects. Often, developers instead create COM add-ins. COM add-ins implement the IDTExtensibility2 interface and can be deployed to other computers.

You can create a COM add-in using unmanaged code (Visual Basic 6.0) or managed code (Visual Basic 2005). With Visual Studio, you can create a managed shared add-in using the Shared Add-in project template, but the preferred method for creating Outlook add-ins is to use the VSTO add-in project template. With VSTO 2005 SE, you can create add-ins for several applications in addition to Outlook (see Chapter 14). The remainder of this chapter focuses on Outlook add-ins created with VSTO (not VSTO 2005 SE), but the descriptions of the Outlook object model are applicable to both.

0 0

Post a comment