Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

Help:Using strings to call subroutines

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
KAB - 28 Nov 2006 20:40 GMT
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

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.