Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default 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,...)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default 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,...)


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default 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.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default 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.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a module from another module Scott Bass[_3_] Excel Programming 5 February 26th 10 03:07 PM
calling a module [email protected] Excel Discussion (Misc queries) 1 September 28th 07 04:03 PM
calling another module from within module rick_mc Excel Programming 2 February 9th 07 07:19 PM
Calling worksheet module from other module. Michael Malinsky Excel Programming 2 December 14th 05 08:47 PM
Calling VBA function that is in another module Jag Man Excel Programming 2 January 7th 04 03:37 AM


All times are GMT +1. The time now is 04:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"