Microsoft Office 2000 Developer   

Creating COM Add-Ins with Visual Basic for Applications

See Also

While you've always been able to use COM add-ins in VBA, in the past another tool, such as Microsoft® Visual C++® or Microsoft® Visual Basic®, was required to create those add-ins. Now you can create your own COM add-ins in VBA with Office 2000 Developer without the need for external development tools.

You can use Add-In Designers to create COM add-ins for use in VBA or any Office application. For example, you might create an add-in tool to format and print code that could be shared with other developers, or you might create an add-in for Microsoft® Excel to calculate tax rates that could be shared with Office users.

COM add-ins created with Office 2000 Developer are packaged as dynamic link libraries (DLL files) and are registered so that they can be loaded by Office 2000 applications. For more information about targeting Office 2000 applications, see "Building Application-Specific Add-ins" in Chapter 11, "Add-ins, Templates, Wizards, and Libraries" of the Microsoft Office 2000/Visual Basic Programmer's Guide.

To add an Add-In Designer to your project

  1. From the File menu, select New Project.

  2. In the New Project dialog box, select Add-In Project.

    An Add-In Designer will be added to your project.

The Add-In Designer provides several properties that can be set to define the attributes of your add-in, including Name, Description, and Load Behavior. It also provides several events that can be used to add code, such as OnConnection, OnStartupComplete, and OnDisconnection. For information about using the Add-in Designer, see "Working with Add-in Designers" in Chapter 11, "Add-ins, Templates, Wizards, and Libraries" of the Microsoft Office 2000/Visual Basic Programmer's Guide.

The actual code for your COM add-in will, of course, depend on what you want the add-in to do as well as which application the add-in is for. Each of the applications that can use COM add-ins exposes its extensibility structure via its object model; you can view the object model for your particular application in the Object Browser. For more information, see "Writing Code in the Add-in Designer" in Chapter 11, "Add-ins, Templates, Wizards, and Libraries" of the Microsoft Office 2000/Visual Basic Programmer's Guide.

To package the COM add-in as a DLL in VBA

After you have written and debugged your code, you can make your add-in into a DLL.

This will create the COM add-in, add the appropriate registry entries, and make the COM add-in available for use in your Office host.

Note   The Microsoft Office 2000/Visual Basic Programmer's Guide uses examples primarily from Visual Basic. Some modifications may be necessary when using the examples in the Visual Basic for Applications environment.

For more information about See
Creating Office-specific COM add-ins Chapter 11, "Add-ins, Templates, Wizards, and Libraries" in the Microsoft Office 2000/Visual Basic Programmer's Guide
Creating COM add-ins (Note the examples given use the object model for Visual Basic; the object model for VBA or Office applications will differ in some respects.) "Extending the Visual Basic Environment with Add-Ins" in the Component Tools Guide section of the Visual Basic documentation
Creating COM Add-Ins using templates in Visual Studio Enhancements for Visual Studio Users