Excel – VBA Cannot return a custom Hashtable from a Public Function

excelvba

I have a Hashtable implementation (in class modules folder).
But I get a strange (long) error, for which no help is provided..
Error throws when I make the Function that return Hashtable Public.
It says:
"Private object modules cannot be used in public object modules as parameters or return types for public procedures (**this is what i need), as public data members, or as fields of public user defined types."

I need very simple logic. I want to be able to get a Function inside one Worksheet to performs some check, fill a Hashtable and return it so I can iterate in it in another Worksheet. Is this even possible (How I do it in C#)

Thanks in advance

Best Answer

The error means that you have your class Instancing property set to Private, which means that you can't use it anywhere where it might get used elsewhere. Mark it as PublicNotCreatable and your error will go away. I'm not clear on what exactly it is you're doing in your app, so that's the first thing to try.