Microsoft Office Tutorials and References
In Depth Information
Tip Developing Add-Ins That Span Multiple Office Applications
It’s possible to develop an add-in that can be used with multiple Office applications. This
can be very useful if you want to write a general-purpose add-in such as an image browser
or a file locator. By using the application object passed to the add-in OnConnection method,
you can determine which application called the add-in and make the appropriate modifica
tions to the menus or information contained in the application.
Modifying the Template
Even though you selected Excel when you ran the wizard, you still need to explicitly add a ref
erence to the Excel TypeLib in your Visual Basic .NET program. You can do this by choosing
Project, Add Reference from the main menu. In the Add Reference dialog box, choose the
COM tab and then select Microsoft Excel 11.0 Object Library. Finally, press the Select button
and then OK to add the reference to your project.
Because the code skeleton created with the Shared Add-In Wizard merely constructs a mini
mal IDTExtensibility2 interface, you’ll need to add your own code to make the add-in do
In this case, we need to declare a module-level variable that contains information about the
button to be added on the toolbar. The following statement defines the MyButton object.
Notice that the WithEvents keyword is included. When the button is pressed in Excel, the
Click event associated with the MyButton object will be fired.
Dim WithEvents MyButton As CommandBarButton