[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 781
  • Last Modified:

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


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.
  • 2
1 Solution
Gustav BrockCIOCommented:
You can't do this directly, but a work around could be:

  Select Case f_name
    Case "Function1"
      Call Function1()
    Case "Function2"
      Call Function1()
    End Select

kplonkAuthor Commented:
Ok thanks
Gustav BrockCIOCommented:
You are welcome.

From Microsoft Visual Basic Help:

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


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now