Creating a COM Add-in for the Visual Basic Editor
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.
For the most part, creating a COM add-in for the Microsoft® Visual Basic® Editor is similar to creating one for a Microsoft® Office XP application. COM add-ins for the Visual Basic Editor also includes the add-in designer or a class module that implements the IDTExtensibility2 library.
One key difference to note is that the initial load behavior setting for a COM add-in for the Visual Basic Editor differs from that of a COM add-in for an Office application. A COM add-in for the Visual Basic Editor can have one of two initial load behaviors: None, meaning that the add-in is not loaded until the user loads it, or startup, meaning that the add-in is loaded when the user opens the Visual Basic Editor.
To create a COM add-in using Visual Basic for Applications in the Visual Basic Editor
Create a new Add-in project, select Visual Basic for Applications IDE in the Application box, and then select VBE 6.0 in the Application Version box. Set the initial load behavior for the add-in to either None or Startup.
Set a reference to the Microsoft Visual Basic for Applications Extensibility 5.3 library in file Vbe6ext.olb.
**Note **If the object library does not appear in the list of available references, you can browse for it in C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6, the default installation directory. The name of the library as it appears in the Object Browser is VBIDE.
The OnConnection event procedure passes in the Application argument, which contains a reference to the instance of the Visual Basic Editor in which the add-in is running. You can use this object to work with all other objects in the VBA Extensibility library. Create a public module-level object variable of type VBIDE.VBE, and assign the object referenced by the Application argument to this variable.
Within the OnConnection event procedure, you can optionally include code to hook the add-in's form up to a command bar control in the Visual Basic Editor. You can work with the Visual Basic Editor's command bars by using the CommandBars property of the VBE object.
Build any forms or other components to be included in the project.
Place a breakpoint in the OnConnection event procedure, and then select Run Project from the Run menu.
In a Visual Basic for Applications (VBA) host application, such as Microsoft® Excel, open the Visual Basic Editor, select Add-In Manager on the Add-Ins menu, and select your add-in from the list. Select the Loaded/Unloaded check box to load the add-in, if it is not set to load on startup.
Debug the add-in. When you have debugged it to your satisfaction, chose Stop Project from the Run menu, end the running project, and make the add-in's DLL by clicking Make projectname.dll on the File menu.
**Note **To test and debug the add-in, you must open another instance of the Visual Basic Editor to see it. The add-in does not appear in the instance of the editor that you are using to create it.
You can use the same strategies to distribute COM add-ins for the Visual Basic Editor as you use to distribute COM add-ins for the Office XP applications.
See Also
Building COM Add-ins for the Visual Basic Editor | Creating COM Add-Ins in Office Developer | Working with the Microsoft Visual Basic for Applications Extensibility 5.3 Library