If you have built an Add-In to contain your Excel custom functions you might have
discovered that, although the functions work fine in an Excel worksheet, you can't
use them in your VBA procedures in other workbooks. It's as if the Visual Basic
Editor can'tse e them. Well, that's because it can't! This article explains how you can
First of all, consider whether this is really what you want to do. Add-Ins are intended
primarily for adding extra functionality to your workbooks. When you load an Excel
Add-In its functionality immediately becomes available to all your workbooks. If you
create a VBA procedure that depends upon a custom function contained in another
workbook, that other workbook would have to be open whenever you wanted to use
its function. The same goes for a custom function in an Add-In. If the Add-In is
loaded that's fine, but supposing you mail your workbook to someone else, or
distribute it to your workgroup. You have to remember to distribute the Add-In too.
It might be simpler to include a copy of the function in the workbook code so your
procedures have direct access to it (you may need to make it a Private Function or
change its name to avoid naming conflicts).
The Visual Basic Editor is behaving as if the function doesn't exist, but I know it does and I can see it if I look at the code inside my Add-In. In fact, the code works fine if I run it from inside my Add-In.
Every workbook has a VBA Project Name. It's calledVB APr o je ct. You can change
that name if you want but normally I don't bother, because normally it doesn't
Did you ever wonder why all the workbooks displayed in the Project Explorer pane of the visual basic editor are called "VBAProject"? If you have any of Microsoft's Add- In's installed you'll see that they have a different name. The Microsoft developers have given their Analysis ToolPak Add-In the VBA Project Name "funcres".
The first thing to do is give your Add-In a unique VBA Project Name. This is because you are going to refer to it by this name in the next step and if there are more than one with the same name the Visual Basic Editor won't know which one to use.
In the Project Explorer pane select the name of your Add-In. If it isn't already open,
display the Visual Basic Editor's Properties Window. You will see that there is only
one property, theName. Type another name and pressEnt er. You will have to obey
the usual naming rules for VBA (i.e. no illegal characters and no spaces). You will see
that the name is immediately applied in the Project Explorer.
In this step you tell the workbook in which you want to use your Add-In's functions that the Add-In exists. You do this by Setting a Reference to the Add-In. You might have come across this technique before if you have wanted to write Excel code to communicate with another program such asO utlo o k orAcce ss.
If it's convenient, restart Excel at this point. This is because your renamed Add-In
will be reloaded and the list you are about to see will be refreshed. If it isn't
convenient, don't bother... read the next paragraph and decide what you want to do.
This action might not be possible to undo. Are you sure you want to continue?