2

In VBA, is there a way to call a function by string value?

For example -

Dim function_name, value1, value2 as String

value1 = "test"
value2 = "Function"
function_name = value1 & value2 ' So function name = 'testFunction'

call function_name ' But this calls a function called 'function_name', where as I require a funtion called 'testFunction'
David Gard
  • 1,527

2 Answers2

4

Try using Application.Run to call it.

Application.Run function_name

CharlieRB
  • 23,021
  • 6
  • 60
  • 107
0

There is a discussion worth mentioning at https://stackoverflow.com/questions/2695198/calling-a-sub-or-function-contained-in-a-module-using-callbyname-in-vb-vba. When you are calling a function that is in a class, not a module, using CallByName from VBA itself gives you a chance to get return values and do error handling. See the linked discussion.