I have a sub
Sub MySub1
MsgBox "I am ok!"
End Sub
Then I have a so called "method sub" with parameters
Sub MySub2 (Parameter1, Parameter2, MethodName)
MsgBox Parameter1
MsgBox Parameter2
MethodName
End Sub
Then I would like to run this whole chain in my master. I have tried the following:
Sub MasterSub
Dim Parameter1 As String
Dim Parameter2 As String
Dim MethodName As String
Parameter1 = "Ou"
Parameter2 = "Yes"
MethodName = MySub1
MySub2 Parameter1, Parameter2, MethodName
Dim
This is giving an error that value or function is expected. How to make this work?
Application.Run
.Select Case
orIf
to run a certain subroutine based on the value of the string...Application.Run "MethodName"
works. I haven't tried second suggestion, but I will check it as wellSub
doesn't return a value.Function
does. That's why when you sayMethodName = MySub1
, this will not assign any value toMethodName
. I suspect that's why you are getting the error. If you convert it to a function, do forget to assign a return value to the function (i.e. before the end ofMySub1
sub, have something like:MySub1 = "This is a test"
)