Can you instantiate classes without hard-coding class names??

A

ALittle

I would like to instantiate classes, which I have written in Excel VBA,
without hard-coding class names..

For example, the following code could set obj to a particular
CodeModule.

Set obj = thisWorkbook.VBProject.VBComponents(indx)

But I really need to instantiate the class that the module represents.
I.e.,

Set obj = new classname
, where classname is thisWorkbook.VBProject.VBComponents(indx).Name.

Any ideas? (If I could accomplish this, it would allow the application
to query all classes in the Class Modules and choose appropriate
classes to process. Hard-coding requires additional redundant code
every time new classes are added.)

Thanks
 
L

Leith Ross

Hello Alittle,

Could you provide a better code example of what you are trying to
accomplish?

Thanks,
Leith Ross
 
A

ALittle

Actually, no. I cannot provide code. That’s what I am looking for.

I want to do the equivalent of

Set obj = new classname

However, the name of any actual class (e.g., classname) is not know
during programming, so the above statement cannot be hard coded. It i
only during program execution that actual class names are known.

This may not be possible except through slight of hand, which I woul
like to avoid.

Possible solutions that I might be forced to try would include:
-- using some type of immediate execution code to execute a characte
string statement or
-- writing code to a class module and then executing that code
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top