Calling one UDF from another in a different module

P

Prof Wonmug

Do I need to do anything special to be able to call one UDF from
another UDF in a different add-in module?

For some reason, I keep getting "Compile Error: Sub or Function not
defined". I have them declared as Public:

Public Function MyUDF(p1,p2,...)
 
P

Paul Robinson

Hi
That should be fine. you must have a problem with the name of the
function or its definition.
regards
Paul
 
P

Prof Wonmug

Hi
That should be fine. you must have a problem with the name of the
function or its definition.
regards
Paul

That's what I thought, but it doesn't work.

I have several personal add-in modules. As far as I know, they are all
standard code modules. Each one is a .xlam file. When I open the
Project Explorer, they are listed along with the VBAPROJECT modules
and they have the same little multi-colored icon as all of the other
code modules.

One of them contains utility functions (UDFs) that I would like to be
able to call from the UDFs in the other modules.

I put the following code in one of the add-in modules:

Public Function a_1(n)
a_1 = a_2(n)
End Function

Public Function a_2(n)
a_2 = n * n
End Function

It works just fine. If I put "=a_1(5)" in a cell, I get the result
"25".

If I move the a_2 function to another module, I get an error message:

Compile Error: Sub or function not defined

just as if the function did not exist.
 
P

Peter T

Are you talking about procedures in different modules in a single workbook,
or modules in different workbook projects.

Regards,
Peter T
 
P

Prof Wonmug

Are you talking about procedures in different modules in a single workbook,
or modules in different workbook projects.

That's the key. I've been doing some more testing.

I have two projects (.xlam files). Each project has 2-3 code modules.

If I call a UDF in a different module in the same project, it works
fine.

It fails it it's in a different project.

Is there a way to make all modules in all projects able to access all
other modules in all other projects?

Or, do I have to qualify the UDF name somehow, like

Call projectname.modulename.udfname(arguments...)

I would like to avoid the latter, if possible, so it will work even if
I move the UDFs to different projects.
 

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