Implementing the IDTExtensibility2 Library

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.

A COM add-in has events that you can use to run code when the add-in is loaded or unloaded, or when the host application has finished starting up or is beginning to shut down. To use these events, you must implement the IDTExtensibility2 library, which provides a programming interface for integrating COM add-ins with their host applications. When you implement the IDTExtensibility2 library within a class module, the library makes a set of new events available to the module. You must have these events to control your COM add-in.

Using the Add-in project in Microsoft® Visual Basic® for Applications (VBA) implements the IDTExtensibility2 library for you in the add-in designer's class module. If you are creating the COM add-in from scratch in Visual Basic 6.0, use the following procedure:

To manually implement the IDTExtensibility2 library in Visual Basic 6.0

  1. Set a reference to the library by clicking References on the Project menu and then selecting the check box next to Microsoft Add-in Designer. If this library does not appear in the list, you can add it by clicking Browse and finding the file Msaddndr.dll. By default, this file is located in the C:\Program Files\Common Files \Designer subfolder.

  2. In the Declarations section of the add-in designer's class module, add the following code:

    Implements IDTExtensibility2
    
  3. In the Code window, click IDTExtensibility2 in the Object box. This adds the template for the procedure to the OnConnection event.

  4. Create event procedure templates for the four remaining event procedures by clicking them in the Procedure dialog box in the Code Window.

  5. Add code or a comment to each of the five event procedures.

    Note   You must include the event-procedure template for each event provided by the IDTExtensibility2 interface. If you omit any of the event procedures, your project will not compile. If you are not adding code to an event-procedure template, it is a good idea to add a comment; a single apostrophe (') is sufficient.

See Also

Writing Code in the Add-in Designer | Working with the IDTExtensibility2 Event Procedures