View Single Post
 
Old 12-05-2013, 03:24 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,369
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by BobBridges View Post
Is there a way in VBA to put the name of a subroutine into a variable and then call it that way, so to speak "indirectly"?
Sure there is! Try:
Code:
Dim MacroName As String, i As Long
 
Sub Demo()
i = CLng(InputBox("Which macro to run?"))
MacroName = "ThisWorkbook.Macro" & i
Application.Run MacroName
End Sub
 
Private Sub Macro1()
MsgBox "Success! You ran macro: " & i
End Sub
 
Private Sub Macro2()
MsgBox "Success! You ran: " & MacroName
End Sub
 
Private Sub Macro3()
MsgBox "Ho hum ... you ran macro 3"
End Sub
Simply input 1, 2 or 3 into the inputbox.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote