2

I have created some custom classes:

  • class1
  • class2
  • class3
  • etc.

I need to create an instance of these classes given the input from an excel worksheet. So the input would return the string, "class1", "class2", "class3", etc.

In vba, I need to be able to say:

Set instanceOfClass = New "class1" 
'using whichever string was returned from the worksheet, if that makes sense?!

Can anyone help; is this even possible?

Thanks

Mike
  • 254
  • 1
  • 6
  • 16
  • Probably wrong, but maybe : `Set instanceOfClass = New Evaluate("class1")` But you may have to create a function that generate an object depending of the string you are inputing : @Comintern : I think that it's the name of the class that is coming as a string, not a parameter. – R3uK Mar 02 '17 at 15:09
  • @R3uK - That makes much more sense. I think I read that completely wrong. – Comintern Mar 02 '17 at 15:13
  • @Comintern : Damn it! I was posting my answer^^, same question indeed, too bad the OP didn't accept the answer! BTW, just a question, does `CreateObject` recognize custom classes? Like `Set instanceOfClass = CreateObject("class1")`? – R3uK Mar 02 '17 at 15:20
  • 1
    FWIW, you should be using a common interface for your class factory (see the linked duplicate) instead of returning `Object`. The calling code seems to point toward the need for some degree of polymorphism. [I'd give this topic in documentation a read.](http://stackoverflow.com/documentation/vba/5357/object-oriented-vba/19071/polymorphism) – Comintern Mar 02 '17 at 15:20
  • 1
    @R3uK - I wish :-P - VBA uses internal CLSID registrations that are only available from the context of the runtime. – Comintern Mar 02 '17 at 15:22
  • @Comintern : I thought so, but I was deeply hoping to be wrong!^^ – R3uK Mar 02 '17 at 15:23

0 Answers0