How to make a custom function to work in another workbook

G

Gerardo

I have one function stored in a module of a workbook, I'll like to use it in
a different workbook. At the begining of the function I used the Public
statement, do I need to do something else? I do keep open the source workbook.

regards
 
C

Chip Pearson

Change the name of the VBProject that contains the function from the default
"VBA Project" to something meaningful like "projMathStuff". To do this, open
the project containing the function, go to the Tools menu in VBA, choose
"VBA Project Properties" and change the value of the Name parameter. Now, to
allow other workbooks to call that function, the other workbook needs to set
a reference to the "projMathStuff" project. In the calling workbook, go back
to the Reference dialog and put a check next to the "projMathStuff" item.
With that reference in place, you can call the function as if it were built
in to the workbook:

Res = TheFucntion(1,2,3)

If there is the possibility that more than one workbook may have a function
named TheFunction, you can prefix the call with the library name. E.g.,.

Res = projMathStuff.TheFunction(1,2,3)


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top