Exposing An Add-In's Routines

The add-in code needs to be accessed from the outside world. One method is to create a custom toolbar with buttons that activate the add-in's macros. There's a way to install the toolbar without any programming at all. Just open the add-in's VBA module and select Attach Toolbars from the Tools menu. Then copy the custom toolbar to the add-in workbook. When a user loads the add-in the toolbar will automatically appear.

Another approach is to declare a public function that starts the add-in's main routine. After loading the add-in the public function appears in the list of "All" and "User Defined" functions shown in the function wizard. Next write a small macro in the personal macro workbook that calls the function. Again it's possible to assign this macro to a toolbar button. Example 8 below illustrates this method. If the add-in is a function library rather than an interactive utility like a wizard, this method works well.

'THIS CODE APPEARS IN PERSONAL.XLS:

Sub StartHistogramWizard()

Dim Ret As Integer

Ret = HistogramWizard(Selection)

End Sub

'THIS CODE APPEARS IN THE ADD-IN:

Public Function HistogramWizard(s As Object) As Integer

'This function starts the histogram wizard.

Call HistoMain(s)

HistogramWizard = 1

End Function

Sub HistoMain(s As Object)

'This is the Main sub in the add-in.

' Initializations...

Example 8. Simple method for exposing add-in routines.

If code in PERSONAL.XLS can't locate the add-in function, use the Tools/References command from the module sheet in PERSONAL.XLS to create a reference to the add-in file.