View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
gromeg gromeg is offline
external usenet poster
 
Posts: 4
Default OO programming in VBA - VBA equivalent to the "eval" function

Hi Everyone,

This problem has been bugging me for the past couple of days. I have
looked for a solution on the web for hours, but wasn't able to get a
satisfactory answer.

Basically, I have a series of modules that have the same structure,
and I'd like to be able to switch from one to another by changing a
cell of my spreasheet. Ideally, my program would look like this :

Public Function MyMainFunction()

Dim moduleName As String

moduleName = Range("A1").Value ' - I select which module to use
from cell A1

result = moduleName.Function1() ' - This doesn't work, since
moduleName is a String

End Function

Unfortunately, it looks like there is no way in VBA to execute a line
such as:

result = Eval( moduleName & ".Function1()")

Or something similar.

Any thought on how I could do this ?

Thanks a lot for your help !!

Jerome