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:
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With