Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#NAME with module and function of the same name

I created a module called foo in my spreadsheet, and then I added the following to it:

Function foo() As Variant
    foo = 5
End Function

When I try to run the function in Excel, by typing =foo() into a cell, I get #NAME. When I look at what #NAME is supposed to mean by clicking on the little icon next to it and then help on this error I get this:

enter image description here

Well, not exactly that, but it was about as useful.

Eventually I discovered that changing the module name to something other than foo seemed to fix it. Have I stumbled upon a bug or a feature? Where is this behavior documented?

like image 519
quant Avatar asked Apr 16 '16 11:04

quant


1 Answers

Since multiple modules are possible and all can have public functions it is also possible that there are multiple public functions with the same name but in different modules. That's why you can call a UDF with =foo.foo(). This is calling the function named "foo" in the module named "foo". That's why =foo() will fail if there is a module named "foo" because foo is first evaluated as the module name.

like image 163
Axel Richter Avatar answered Oct 07 '22 19:10

Axel Richter