ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can you instantiate classes without hard-coding class names?? (https://www.excelbanter.com/excel-programming/346363-can-you-instantiate-classes-without-hard-coding-class-names.html)

ALittle

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

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


--
ALittle
------------------------------------------------------------------------
ALittle's Profile: http://www.excelforum.com/member.php...o&userid=28695
View this thread: http://www.excelforum.com/showthread...hreadid=487484


Leith Ross[_309_]

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

Hello Alittle,

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

Thanks,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=487484


ALittle[_2_]

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

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

--
ALittl
-----------------------------------------------------------------------
ALittle's Profile: http://www.excelforum.com/member.php...fo&userid=2869
View this thread: http://www.excelforum.com/showthread.php?threadid=48748



All times are GMT +1. The time now is 06:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com