From: Prof Wonmug on 27 Apr 2010 18:59 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,...)
From: Paul Robinson on 28 Apr 2010 07:03 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 <won...(a)e.mcc> 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,...)
From: Prof Wonmug on 28 Apr 2010 08:23 On Wed, 28 Apr 2010 04:03:42 -0700 (PDT), Paul Robinson <paul.robinson(a)it-tallaght.ie> 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.
From: Peter T on 28 Apr 2010 11:55 Are you talking about procedures in different modules in a single workbook, or modules in different workbook projects. Regards, Peter T "Prof Wonmug" <wonmug(a)e.mcc> wrote in message news:eh9gt51fcel36k65qtfhp49t44seiems2n(a)4ax.com... > On Wed, 28 Apr 2010 04:03:42 -0700 (PDT), Paul Robinson > <paul.robinson(a)it-tallaght.ie> 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.
From: Prof Wonmug on 28 Apr 2010 13:24
On Wed, 28 Apr 2010 16:55:35 +0100, "Peter T" <peter_t(a)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. |