Hi All
I'm wondering if any body knows how to call a subroutine from a string. For
example:
Dim TestString as string
TestString = "MySubroutine(Data)"
'***The question I have would be: How to use TestString to call
MySubroutine(Data).
Thank You
KAB
Greg Maxey - 28 Nov 2006 20:50 GMT
Something like this perhaps:
Sub ScratchMacro()
Dim TestString As String
Dim PassString As String
PassString = "Who's your uncle?"
TestString = MySubRoutine(PassString)
MsgBox TestString
End Sub
Function MySubRoutine(Data As String)
MySubRoutine = "Bob's your uncle"
End Function
> Hi All
> I'm wondering if any body knows how to call a subroutine from a string. For
[quoted text clipped - 7 lines]
> Thank You
> KAB
crz - 28 Nov 2006 21:33 GMT
Is this what you meant?
Sub Test()
Dim s As String
s = "Curly"
Application.Run s
s = "Larry"
Application.Run s
s = "Moe"
Application.Run s
End Sub
Sub Curly()
MsgBox "I'm Curly"
End Sub
Sub Larry()
MsgBox "I'm Larry"
End Sub
Sub Moe()
MsgBox "I'm Moe"
End Sub
You can also pass parmeters to those macros as well. See the docs for details.

Signature
-Chris
> Hi All
> I'm wondering if any body knows how to call a subroutine from a string. For
[quoted text clipped - 7 lines]
> Thank You
> KAB
Klaus Linke - 29 Nov 2006 07:33 GMT
> Hi All
> I'm wondering if any body knows how to call a subroutine from a string.
[quoted text clipped - 8 lines]
> Thank You
> KAB
Hi KAB,
Also look at the VBA help on CallByName ... You'd need to pass the macro
name and arguments separately though.
Klaus