excel vba - macro calling anoter macro ?

%3CLINGO-SUB%20id%3D%22lingo-sub-1354418%22%20slang%3D%22en-US%22%3Eexcel%20vba%20-%20macro%20calling%20anoter%20macro%20%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1354418%22%20slang%3D%22en-US%22%3E%3CP%3Eexcel%20vba%20-%20how%20can%20I%20from%20macro%20calling%20anoter%20macro%20%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1354418%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1354446%22%20slang%3D%22en-US%22%3ERe%3A%20excel%20vba%20-%20macro%20calling%20anoter%20macro%20%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1354446%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F644966%22%20target%3D%22_blank%22%3E%40ariellavy%3C%2FA%3E%26nbsp%3BThe%20simplest%20way%20is%20to%20just%20type%20the%20name%20in%20your%20routine.%20Below%20are%20two%20examples.%20The%20first%20example%20(%231%20and%20%232)%20show%20how%20to%20call%20one%20from%20another.%20The%20second%20example%20(%233%20and%20%234)%20show%20how%20to%20call%20one%20and%20also%20pass%20a%20parameter%20to%20another%20routine.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3ESub%20Routine1()%0A%20%20%20%20MsgBox%20%22Hello%2C%20I'm%20%231%22%0A%20%20%20%20Routine2%0AEnd%20Sub%0A%0A%0ASub%20Routine2()%0A%20%20%20%20MsgBox%20%22Hello%2C%20I'm%20%232%22%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3ESub%20Routine3()%0A%20%20%20%20Routine4%20%22Hello%2C%20I'm%20originally%20from%20%233%2C%20but%20am%20now%20in%20%234!%22%0AEnd%20Sub%0A%0A%0ASub%20Routine4(ByVal%20Message%20As%20String)%0A%20%20%20%20MsgBox%20Message%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHTH%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Visitor

excel vba - how can I from macro calling anoter macro ?

1 Reply
Highlighted

@ariellavy The simplest way is to just type the name in your routine. Below are two examples. The first example (#1 and #2) show how to call one from another. The second example (#3 and #4) show how to call one and also pass a parameter to another routine.

 

Sub Routine1()
    MsgBox "Hello, I'm #1"
    Routine2
End Sub


Sub Routine2()
    MsgBox "Hello, I'm #2"
End Sub

 

Sub Routine3()
    Routine4 "Hello, I'm originally from #3, but am now in #4!"
End Sub


Sub Routine4(ByVal Message As String)
    MsgBox Message
End Sub

 

HTH