PDA

View Full Version : Call Two different Macros using IF



gvreddyhr
10-30-2011, 12:49 AM
Hi,

Thank you all for your timely support, I want to call two macros based on if condition, but I am not able to do it, can anyone tell me where am I going wrong..

Sub 2macrosusingif ()
Dim MyInput
MyInput = InputBox("Please Specify which macro needs to be called (send , Display) ")
If Myinput = Send then
Call Send()
Else if MyInput = Display then
Call Display()
End if
End Sub


Regards,
GV Reddy

omp001
10-30-2011, 06:08 AM
Hi. Try this way:
Sub TwoMacrosUsingIf()
Dim MyInput
MyInput = InputBox("Please Specify which macro needs to be called (Send , Display) ")
If MyInput = "Send" Then
Call Send
Else
If MyInput = "Display" Then
Call Display
End If
End If
End Sub

mikerickson
10-30-2011, 08:13 AM
A very similar coding would be this. Note the keyword ElseIf without a space.
If MyInput = "Send" Then
Call Send
ElseIf MyInput = "Display" Then
Call Display
End If

I'd also change to a case insensitive testIf LCase(MyInput) = "send" Then

Or you could use Application.Run instead of Calling the sub.


Sub mySub()
Dim MyInput As String

MyInput = InputBox("Please Specify which macro needs to be called (Send , Display) ")
If StrPtr(MyInput) = 0 Then Exit Sub: Rem cancel pressed

Application.Run MyInput
End Sub