MS-Excel / Excel 2003

Saving Custom Functions in an Excel Add-in

The only limitation to user-defined functions is that when you enter them directly into a cell (without the use of the Insert Function dialog box), you must preface their function names with their filenames. For example, if you want to type in the custom Commission function that's saved in the Personal Macro Workbook and you enter the following formula:


(assuming that cell C9 contains the total sales and cell C10 contains the number of items sold), Excel returns the #NAME? error value to the cell. If you then edit the function to include the Personal Macro Workbook's filename as follows:


Excel then calculates the sales commission based on the TotalSales in C9 and the ItemsSold in C10, returning this calculated value to the cell containing this user-defined function.

To be able to omit the filenames from custom functions when you enter them directly into a cell, you need to save the workbook file that contains them as a special add-in file. Then, after saving the workbook with your user-defined functions as an add-in file, you can start entering the functions into any worksheet sans their filename qualifiers by activating the new add-in file in the Add-Ins dialog box (Tools →Add-Ins).

To convert a workbook containing the user-defined functions that you want to be able to enter into worksheets without their filenames, follow these steps:

  1. Open the workbook in which you've saved your user-defined functions in Excel.
    Make sure that each custom function works properly.
  2. Press Alt+F11 or choose Tools → Macro → Visual Basic Editor to open Visual Basic Editor.
  3. Choose Tools → VBAProject Properties from Visual Basic Editor's menu bar to open the VBAProject - Project Properties dialog box.
  4. Select the Protection tab and then select the Lock Project for Viewing check box.
    Selecting this check box prevents other users from viewing the custom functions so that they can't make any changes to them.
  5. Select the Password text box, enter the password there, and then select the Confirm Password text box and re-enter the password exactly as you entered it in the text box above. Then click OK.
    This password prevents users from removing the view-protection status.
  6. Click the View Microsoft Excel button at the beginning of the Standard toolbar in the Visual Basic Editor window to return to the Excel worksheet.
  7. Choose File → Properties to open the Properties dialog box.
  8. Enter a descriptive title for the add-in in the Title text box, enter a description of its contents in the Comments text box, and then click OK.
    Before saving the workbook as an add-in, you should add a title and description of the userdefined functions that it contains. (This information then appears in the Add-Ins dialog box whenever you select the add-in file.)
    After you click OK, you're ready to save the workbook file as a special add-in file.
  9. Choose File → Save As to open the Save As dialog box.
  10. From the Save as Type drop-down list, select Microsoft Excel Add-In (*.xla).
    This action selects the Add-Ins folder in the Save In drop-down list box showing the names of any add-in files that you've saved there.
  11. Select the File Name drop-down list box and replace the current filename with one of your own (without changing the .xla filename extension) and then click the Save button.
    After saving your workbook as an add-in file, you need to follow the remaining steps to activate it so that you can enter its user-defined functions in any worksheet.
  12. Choose Tools → Add-Ins to open the Add-Ins dialog box.
  13. Click the Browse button in the Add-Ins dialog box to open the Browse dialog box.
  14. Select the name of your new add-in file in the Browse list box and then click OK.
    The Browse dialog box closes, and you return to the Add-Ins dialog box.
  15. Select the check box in front of the name of the new add-in and then click OK to close the Add- Ins dialog box.
    This action activates the add-in so that you can enter its user-defined functions in any worksheet.

After you close the Add-Ins dialog box, you can start entering the custom functions that this add-in file contains directly into the cells of any spreadsheet without having to open the Insert Function dialog box.

[Previous] [Contents]