Page 287 - Microsoft Office Excel 2003 Programming Inside Out
P. 287

Creating Add-Ins and COM Add-Ins

                             When the application is ready to end, you need to properly remove the button using code like
                             the OnBeginShutdown routine. The button’s Delete method is used to actually remove the
                             button from the toolbar. Then the resources associated with the button object are destroyed
                             by setting the MyButton object to Nothing.

                             Public  Sub  OnBeginShutdown(ByRef  custom  As  System.Array)  _
                                 Implements  Extensibility.IDTExtensibility2.OnBeginShutdown

                                 MyButton.Delete()
                                 MyButton  =  Nothing

                             End  Sub
                             Finally, the code associated with the button’s click event is called whenever My Button is
                             pressed on the toolbar. As you can see in this example, the MyButton_Click routine merely
                             calls the MsgBox routine to display a simple message on the screen. However, in a more complex
                             add-in, routines like this will handle the interactions associated with the add-in for the user.

                             Private  Sub  MyButton_Click(ByVal  Ctrl  As  _
                                 Microsoft.Office.Core.CommandBarButton,  _
                                 ByRef  CancelDefault  As  Boolean)  Handles  MyButton.Click
                                  MsgBox("My  button  was  clicked")

                             End  Sub

                    Installing the Add-In

                             To install the add-in, you must first build it. Then you must build the installation program
                             and finally run the installation program.
                               1	 Choose Build, Build Solution from the Visual Studio .NET main menu. This will
                                  compile your add-in.
                               2	 The next step is to build the installation program. This is done by right-clicking the
                                  Setup project in the Solution Explorer and choosing build from the context menu.
                                                                                                             Chapter 11
                             Note  The installation package created by the add-in wizard does not include the .NET
                             Framework, which must be installed prior to installing your add-in. If you already have
                             Visual Studio .NET installed on your computer, you also have installed the .NET Framework.

                               3	 Once the build is complete, right-click the Setup project again and choose Install from
                                  the popup menu. This will run the MyCOMAddinSetup Setup Wizard, which will
                                  guide the user through the steps required to install the add-in on the user’s computer.








                                                                                                       261
                                                                                                Part 4:  Advanced VBA
   282   283   284   285   286   287   288   289   290   291   292