Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
6Activity
0 of .
Results for:
No results containing your search query
P. 1
How to Use Your Excel Add-In Functions in VBA

How to Use Your Excel Add-In Functions in VBA

Ratings: (0)|Views: 410|Likes:
Published by api-27228698

More info:

Published by: api-27228698 on Dec 02, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

How to Use Your Excel Add-In Functions in VBA
Is There a Problem?

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
fix that.

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).

I'm not saying don't do it. You just need to think about it first, and if you're sure the
Add-In will be available, then go ahead. Here's how...
When Does the Problem Arise?
I'm writing a procedure for one of my workbooks. In my procedure I want to use the
RemoveSpaces function that I created a while ago and saved in my Martin's
Functions Add-In which is currently installed in my copy of Excel. But when I try to
run my procedure I get an error.

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.

I need the Visual Basic Editor to be able tose e the functions in my Add-In from
inside the code module of adiffe r e nt workbook.
Give Your Add-In a VBA Project Name

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
matter.

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.

>>>
Now save the changes to your Add-In. Make sure your Add-In is selected in the
Project Explorer and choose File > Save.
Set a Reference to the Add-In

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.

Activity (6)

You've already reviewed this. Edit your review.
1 hundred reads
Rishendy liked this
hanbals liked this
vjsingh01 liked this
zabidi1 liked this
nanuv liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->