Using Excel Add-Ins to Share VBA Code
Part four of a four-part series of blogs

If you've written a killer function, you'll want to be able to share it between workbooks. The best way to do this is using an add-in.

  1. Sharing Code across Workbooks using Add-Ins
  2. Useful Examples of Code to Share
  3. Creating an Add-In
  4. Using Add-In Functions (this blog)

This blog is part of our Excel VBA online tutorial.  Wise Owl also run excellent classroom-based VBA courses!

Posted by Andy Brown on 05 March 2012

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Using Add-In Functions

The previous parts of this blog show you how to create add-ins; it's time now to use them.  To do this, you must link to the add-in.

Using Add-In Functions in Excel

To add a reference for an add-in that you've created, show the Excel options dialog box:

Excel 2010 options Excel 2007 options
Using Excel 2010 Using Excel 2007

You can now go to the Add-Ins dialog box:

Excel Options dialog box

To show the Add-Ins dialog box:

 

In Excel 2010 you can also click on the Add-Ins tool on the Developer tab of the ribbon.

You can now choose the add-in(s) that you want to load:

Add-ins dialog box

Tick each add-in that you want to load (here we've ticked WiseOwlCode).

You can now use any of the functions in your add-in within any Excel workbook (this will be true even after you exit Excel and go back in):

Excel add-in functions being used  

Here we've used functions to return people's full names, the path to where files are stored and whether particular worksheets exist or not.

Using the Function Wizard to Include Functions

You'll find it easier to get at functions if you use the function wizard:

The function wizard tool

Click on this tool to insert a function.

 

You can then select the User  Defined category (as shown here) to display a list of all the functions in your add-in:

User-defined functions list

When you choose User Defined, you can see the functions you've written and shared.

Using Add-In Functions and Procedures in VBA 

To use a function in an add-in, first include the add-in in Excel (as shown above) , then reference it:

Add-in code not being found

We're writing a module in a new workbook, and our DoesWorksheetExist function doesn't seem to exist.

 

First go into the References dialog box: 

Tools References menu

Select Tools --> References from the menu in the VBA code editor.

 

Now tick the box next to the add-in whose code you want to use:

Tick box in References dialog box

Tick (in this case) the WiseOwlCode application.

You can now use any code in your referenced add-in:

Reference detected

That's more like it! The DoesWorksheetExist function is in a referenced application.

 

I'd recommend qualifying the function name with the object library to which it belongs:

Qualified reference

If you type in the name of the add-in project, the code completes automatically.

 

 

This blog has 0 threads Add post