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

Creating Add-Ins and COM Add-Ins

                    Installing an Add-In
                             To install an add-in, simply place a check mark next to the add-in you wish to use in the
                             Add-in Manager and click OK. The add-in will be immediately loaded and will be available
                             for your use.


                             Note  Other Microsoft products such as Microsoft MapPoint might install add-ins that you
                             can load into Excel.

                             If the add-in you wish to use isn’t listed in the Add-Ins dialog box, press the Browse button
                             to locate the add-in you wish to use. By default, user-created add-ins are stored in the
                             \Documents and Settings\User\Application Data\Microsoft\AddIns folder; however, they
                             may be located in any folder you choose.

                             Note  If any of the add-ins supplied with Excel aren’t shown in the Add-Ins dialog box, use
                             the setup disk to install the add-in you wish to use.


                    Unloading an Add-In
                             Once an add-in is loaded, it remains loaded until you explicitly unload it with the Add-Ins
                             dialog box. To unload an add-in, simply uncheck the check box next to the name of the
                             add-in that you wish to unload and press OK. The next time Excel is started, the add-in won’t
                             be loaded.

                             Note  If you remove an add-in, any formulas that reference functions in the add-in will be
                             updated to reflect the file name of the workbook containing the add-in. If you reload the
                             same add-in, the formulas will be restored to their original form.



                    Creating Excel Add-Ins
                             An Excel add-in is merely a special type of workbook that includes a set of macros and func­
                                                                                                             Chapter 11
                             tions that perform whatever tasks you want.

                    Creating an Add-In

                             Suppose you have a worksheet that computes a discounted value based on the list price and
                             the discount. It might look something like the following code:
                             Public  Function  DiscountedPrice(ListPrice,  Discount)  As  Currency

                             If  Discount  <=  1  And  Discount  >=  0  Then
                                 DiscountedPrice  =  ListPrice  *  (1  - Discount)




                                                                                                       241
                                                                                                Part 4:  Advanced VBA
   262   263   264   265   266   267   268   269   270   271   272