Excel 2007 Power Programming with VBA (Mr. Spreadsheets Bookshelf)
As I note earlier, you can convert any workbook to an add-in, but not all workbooks are appropriate candidates for add-ins. First, an add-in must contain macros ( otherwise , it's useless).
Generally, a workbook that benefits most from being converted to an add-in is one that contains general-purpose macro procedures. A workbook that consists only of worksheets would be inaccessible as an add-in because worksheets within add-ins are hidden from the user . You can, however, write code that copies all or part of a sheet from your add-in to a visible workbook.
Creating an add-in from a workbook is simple. The following steps describe how to create an add-in from a normal workbook file:
-
Develop your application and make sure that everything works properly.
Don't forget to include a way to execute the macro or macros in the add-in. You might want to add a new command to the Ribbon or a new menu item to a shortcut menu. See Chapters 22 and 23 for more information about modifying Excel's user interface.
-
Activate the Visual Basic Editor (VBE) and select the workbook in the Project window. Choose Tools
xxx Properties (where xxx represents the name of the project) and then click the Protection tab. Select the Lock Project for Viewing check box and then enter a password (twice). Click OK. A Few Words about Passwords Microsoft has never promoted Excel as a product that creates applications in which the source code is secure. The password feature provided in Excel is sufficient to prevent casual users from accessing parts of your application that you'd like to keep hidden. Excel 2002 and later versions include stronger security than previous versions, but your passwords can be cracked. If you must be absolutely sure that no one ever sees your code or formulas, Excel is not your best choice as a development platform.
This step is necessary only if you want to prevent others from viewing or modifying your macros or UserForms.
-
Reactivate Excel and choose Office
Prepare Properties to display the Document Properties panel. Enter a brief descriptive title in the Title field and a longer description in the Comments field. This step is not required, but it makes the add-in easier to use by displaying descriptive text in the Add-Ins dialog box.
-
Choose Office
Save As to display the Save As dialog box. -
In the Save As dialog box, select Excel Add-In (*.xlam) from the Save as Type drop- down list.
-
Click Save. A copy of the workbook is saved (with an .xlam extension), and the original workbook remains open .
-
Close the original workbook and then install the add-in version.
-
Test the add-in to make sure it works correctly. If not, make changes to your code. And don't forget to save your changes.
Caution | A workbook being converted to an add-in must have at least one worksheet. For example, if your workbook contains only chart sheets or Excel 5/95 dialog sheets, the Excel Add-In (*.xlam) option does not appear in the Save As dialog box. Also, this option appears only when a worksheet is active when you choose the Office |