Is there a way to Call a macro from within another.

I have a password protected macro that works great by itself. I created my own macro but need to call that protected one first. Trying to get by without having to hit two macros to get the end result. 

  • Myron,

    You can use GMSManager.RunMacro to do this:

    GMSManager.RunMacro

    Function RunMacro(ModuleName As String, MacroName As String, Parameter() As Variant) As Variant

    Here is the example from the help file:

    Sub MyTestSub() 
     MsgBox "Hello world!" 
    End Sub 
    
    Sub Test() 
     GMSManager.RunMacro "GlobalMacros", "MyModule.MyTestSub" 
    End Sub 
    
    'The following function is contained in the module "MyModule" which is part of the GMS file "GlobalMacros." 
    Function Multiply(x As Double, y As Double) As Double 
     Multiply = x * y 
    End Function 
    
    Sub Test() 
     Dim v As Double 
     v = GMSManager.RunMacro("GlobalMacros", "MyModule.Multiply", 4, 7) 
     MsgBox "4 * 7 = " & v 
    End Sub 
    

    Hopefully that helps,

    -Shelby

    • Not having much luck with it.

      The protected macro I'm trying to call doesn't fall under GlobalMacros

      Tried many different variables but can't get it to call the macro I need after after doing my macro

      • Myron,

        It does not have to be GlobalMacros, you just need the ModuleName. So Here is an example of my GMS:

        And I can call it from somewhere else like this:

        Sub TryThis1()
            GMSManager.RunMacro "ASampleGMS", "Macros.SayHello"
        End Sub
        

        Hope that helps,

        -Shelby

        • If ASampleGMS is password protected then you can't add the Macros under Module. I need something like this

          Sub DoThis()
          run my code then
          Call ProtectedMacro
          End Sub
          • Got it! Holy cow that was tough! The wording has to be exact! Thanks Shelby.
            • I came across a scenario where I actually needed this today! Worked as needed!