Programmatically generate name of functition to call

  • Thread starter Thread starter Mel
  • Start date Start date
M

Mel

I want to use a string variable to formulate the name of
the function to call, I can create the name in a string
variable, but how do you use the variable to call the
function.
e.g. Str1=MyFunction1
I tried str1(arg1) and it didnt work.
If I use Myfunction1(arg1) then it works . I know there
must be a special way to call functions if the name is in
a variable. Thanks
 
I believe you are looking for the "Run" command. Here's a small demo.

Function MyFunction(x)
MyFunction = 2 * x
End Function


Sub Main()
Dim n
Dim s

s = "MyFunction"
n = 3

Debug.Print Run(s, n)
End Sub

HTH. :>)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top