ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Calling one UDF from another in a different module (https://www.excelbanter.com/excel-programming/442096-calling-one-udf-another-different-module.html)

Prof Wonmug

Calling one UDF from another in a different module
 
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,...)

Paul Robinson

Calling one UDF from another in a different module
 
Hi
That should be fine. you must have a problem with the name of the
function or its definition.
regards
Paul

On Apr 27, 11:59*pm, Prof Wonmug wrote:
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,...)



Prof Wonmug

Calling one UDF from another in a different module
 
On Wed, 28 Apr 2010 04:03:42 -0700 (PDT), Paul Robinson
wrote:

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.

Peter T

Calling one UDF from another in a different module
 
Are you talking about procedures in different modules in a single workbook,
or modules in different workbook projects.

Regards,
Peter T

"Prof Wonmug" wrote in message
...
On Wed, 28 Apr 2010 04:03:42 -0700 (PDT), Paul Robinson
wrote:

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.




Prof Wonmug

Calling one UDF from another in a different module
 
On Wed, 28 Apr 2010 16:55:35 +0100, "Peter T" <peter_t@discussions
wrote:

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.

Peter T

Calling one UDF from another in a different module
 
Either you need to set relevant references or use Application.Run

Regards,
Peter T

"Prof Wonmug" wrote in message
...
On Wed, 28 Apr 2010 16:55:35 +0100, "Peter T" <peter_t@discussions
wrote:

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.





All times are GMT +1. The time now is 08:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com