Q) How can I call a Function by using a variable instead of
Function Name?
(A) Use the Eval Function. If you pass to the Eval function a string
that contains the name of a function, the Eval function returns the return value of the
function. For example, Eval("Chr$(65)") returns "A".
So for example, in the following code, if you call fEval with "A" as
parameter, you should get the result "Test That", else "Test This".
Function fEval(status As String)
Dim strFunctionName As String
Dim x
If status = "A" Then
strFunctionName = "TestThat()"
Else
strFunctionName = "TestThis()"
End If
fEval = Eval(strFunctionName)
End Function
Function TestThis()
Debug.Print "Test This"
End Function
Function testThat()
Debug.Print "Test That"
End Function
|