Mackro

N

Nyheder

Hey, is it possible to start a Macro from within another Macro.

How is it done.

Thanks in advance
 
J

Jim Cone

Enter the name (nothing else) of the second macro on its own line.


Hey, is it possible to start a Macro from within another Macro.

How is it done.

Thanks in advance
 
D

Dave Peterson

I like to use the Call keyword:

Sub Mac1()
Call Mac2
End Sub

Sub Mac2
msgbox "I'm in mac2"
End sub
 
H

Harald Staff

Ditto that. It documents itself. And it is far more readable when variables
are passed:


Sub Main()
' ugly confusing code:
NoHands
MyWarningSubroutine "Pay!", 8, "Yo!"

' vs sensible code:
Call NoHands
Call MyWarningSubroutine("Pay!", 9, "Yo!")
End Sub

Sub NoHands()
MsgBox "Attention", vbCritical
End Sub

Sub MyWarningSubroutine(Msg As String, _
WarningNo As Long, _
Caption As String)
MsgBox Msg & vbNewLine & vbNewLine & _
"This is warning #" & WarningNo, , Caption
End Sub
 
D

Dave Peterson

And I like specifying the parms by name:

Call MyWarningSubroutine("Pay!", 9, "Yo!")
becomes:
Call MyWarningSubroutine(Msg:="Pay!", WarningNo:=9, Caption:="Yo!")

Then when (not if!) I copy that line of code, I don't have to remember what
order those passed values have to be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top