+ Reply to Thread
Results 1 to 3 of 3

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

  1. #1
    Registered User
    Join Date
    11-09-2005
    Posts
    2

    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

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Alittle,

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

    Thanks,
    Leith Ross

  3. #3
    Registered User
    Join Date
    11-09-2005
    Posts
    2
    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 known during programming, so the above statement cannot be hard coded. It is only during program execution that actual class names are known.

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

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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1