Compartilhar via


Building COM Add-ins 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.

By creating COM add-ins for the Visual Basic Editor, you can customize your development environment and work with components in a VBA project from code. For example, you can build a code wizard that walks a programmer through a series of steps and then builds a procedure. Or you can build a code analyzer that determines how many times and from where a procedure is called. Creating COM add-ins for the Visual Basic Editor is one way to make your own job easier!

When you create a COM add-in for the Visual Basic Editor, it appears in all instances of the Visual Basic Editor. You can't, for example, create a COM add-in that appears only in the Visual Basic Editor in Word; it will also appear in the Visual Basic Editor in Access, Excel, PowerPoint, FrontPage, and any other VBA host applications on the computer where the COM add-in DLL is registered.

Note also that you can create multiple add-ins in a single DLL. Each add-in designer in the add-in project represents a separate add-in. For example, you can create a single DLL that contains a suite of add-ins for developers, and the developers can load just the add-ins they want to use.

To control the Visual Basic Editor from the code inside an add-in, you use the Microsoft Visual Basic for Applications Extensibility 5.3 library. This object library contains objects that represent the parts of a VBA project, such as the VBProject object and the VBComponent object. The top-level object in the VBA Extensibility library object model is the VBE object, which represents the Visual Basic Editor itself. For more information about this object library, use context-sensitive Help (F1) in the Object Browser. For a diagram of its objects, see the .

Note   Don't confuse the VBA Extensibility library with the IDTExtensibility2 library. Although their names are similar, the VBA Extensibility library provides objects that you can use to work with the Visual Basic Editor from an add-in while it is running, and the IDTExtensibility2 library provides events that are triggered when the add-in is connected or disconnected. In addition, don't confuse the VBA Extensibility library with the Microsoft Visual Basic 6.0 Extensibility library, which is used for creating add-ins in Microsoft Visual Basic.

To see a sample COM add-in for the Visual Basic Editor, copy the DevTools project from the ODETools\V9\Samples\OPG\Samples\CH11\DevTools subfolder on the Office 2000 Developer CD-ROM to your computer. The DevTools sample project includes two simple add-ins that work with objects in the VBA Extensibility library. The Insert Procedure Template add-in found in this project inserts a new procedure skeleton into a selected code module, complete with scoping, arguments, a return value, and simple error handling. The PathFinder add-in saves you from having to type long file paths — you can use it to navigate to the file you're interested in, and then copy a string containing the file path.