Context: I am trying to dynamically call a method via VBA's Application.Run function and pass parameters to the method, dynamically. More of a proof of concept than an actual use case.
Code:
Public Sub Test()
Call MethodDynamically("MethodToBeCalled", "This doesnt, work")
End Sub
Public Sub MethodDynamically(MethodName As String, Params As String)
Application.Run MethodName, Params
End Sub
Public Sub MethodToBeCalled(Param1 As String, Param2 As String)
Debug.Print Param1 & " " & Param2
End Sub
Error: Running the Test method I receive Run-time error '449': Argument not optional on the Application.Run line in the MethodDynamically method.
Expectation: My desire is that running the Test method will trigger MethodToBeCalled with This doesnt and work being passed as parameters. The result would be This doesnt work in the Immediate Window.