Link to home
Start Free TrialLog in
Avatar of kplonk
kplonk

asked on

Execute a function in vba where the function name is a variable

Hi,

what i want to do is have a table that has the name of a function in one of the fields, i want some VBA code to read this table and load the list of function names, i think they will be strings at this point, then i want to call each of the functions in this list.

Getting the table and the list is not an issue so lest assume i have a recoed set and can loop over it, then i have the fields saved as a string so i have a string lets call it f_name, what i want to do is call or execute this function?

can this be done.
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kplonk
kplonk

ASKER

Ok thanks
You are welcome.

/gustav
From Microsoft Visual Basic Help:

Example
The following example assumes that you have a series of 50 functions defined as A1, A2, and so on. This example uses the Eval function to call each function in the series.


Sub CallSeries()
 
    Dim intI As Integer
 
    For intI = 1 To 50
        Eval("A" & intI & "()")
    Next intI
 
End Sub

Open in new window