locked
call macro RRS feed

  • Question

  • Can one macro call another macro? How do call a macro with parameters?
    Thursday, May 5, 2011 3:04 AM

Answers

  • Strictly speaking, a macro is a procedure (sub) without arguments, but yes, it is possible to call one procedure from another, either by simply using its name or by using the keyword Call.

    For example:

    Sub Proc1()
        MsgBox "Hello World"
    End Sub

    Sub Proc2(MyText As String)
        MsgBox MyText
    End Sub

    Sub Proc3()
        Proc1
    End Sub

    Sub Proc4()
        Call Proc1
    End Sub

    Sub Proc5()
        Proc2 "To be or not to be"
    End Sub

    Sub Proc6()
        Call Proc2("To be or not to be")
    End Sub

    Note the absence of parentheses when calling Proc2 without the keyword Call


    Regards, Hans Vogelaar
    • Proposed as answer by Cindy Meister MVP Thursday, May 5, 2011 6:35 AM
    • Marked as answer by Tessa75 Thursday, May 5, 2011 12:33 PM
    Thursday, May 5, 2011 5:50 AM

All replies

  • Strictly speaking, a macro is a procedure (sub) without arguments, but yes, it is possible to call one procedure from another, either by simply using its name or by using the keyword Call.

    For example:

    Sub Proc1()
        MsgBox "Hello World"
    End Sub

    Sub Proc2(MyText As String)
        MsgBox MyText
    End Sub

    Sub Proc3()
        Proc1
    End Sub

    Sub Proc4()
        Call Proc1
    End Sub

    Sub Proc5()
        Proc2 "To be or not to be"
    End Sub

    Sub Proc6()
        Call Proc2("To be or not to be")
    End Sub

    Note the absence of parentheses when calling Proc2 without the keyword Call


    Regards, Hans Vogelaar
    • Proposed as answer by Cindy Meister MVP Thursday, May 5, 2011 6:35 AM
    • Marked as answer by Tessa75 Thursday, May 5, 2011 12:33 PM
    Thursday, May 5, 2011 5:50 AM
  • Thank you Hans
    Thursday, May 5, 2011 12:34 PM