Microsoft Office Tutorials and References
In Depth Information
Choose Project, References from Visual Basic’s main menu, and add the Microsoft
Excel 11.0 Object Library to the list of references in this application.
View the code associated with the designer by pressing the View Code icon in the
Project Explorer or by right-clicking the designer’s name and choosing the View Code
command. Because the add-in template is geared toward developing add-ins for
Visual Basic, you can delete almost all the code in the module. (See the following tip.)
Tip Using Option Explicit
Don’t delete the Option Explicit statement at the start of the code. Option Explicit forces you
to define a variable with a Dim , a Public , or a Private statement before you use it. This helps
you track down misspelled variables and variables that forgot to define at the module level.
It’s definitely a timesaver, and I strongly recommend that every Visual Basic module you
write should include Option Explicit as its first statement.
Add the code found on page 251. Select File, Make Project from Visual Basic’s main
menu. This will create the DLL file containing the automation add-in. Then start
Excel, and choose Tools, Add-Ins to display the Add-Ins dialog box. After that, press
the Automation button to display the list of automation servers available on the sys
tem. Look for the project name in the list of automation servers to find the one you
just created. Select the appropriate automation server, and press OK.