I'm a freshman in college. We were assigned and excel project. We're recording macros and using VBA to edit them. All I need to know is how to make a sort of master macro to call on all the ones I have made at once. Help is much appreciated.
I'm a freshman in college. We were assigned and excel project. We're recording macros and using VBA to edit them. All I need to know is how to make a sort of master macro to call on all the ones I have made at once. Help is much appreciated.
Hello Mac3188,
Create a Sub procedure in a Standard VBA Module and list the macro you have already created in it. Calling this one macro will then execute all the macro inside of it one by one.
Example:
Be sure to include any arguments your macros use as well.![]()
Sub MasterMacro() Call Macro1 Call Macro2 End Sub
Sincerely,
Leith Ross
Thank you very much.
There are several options, with no "best answer".
One option is simply to list the names of each subroutine.
If any of the macros require that you pass arguments, simply list the arguments:![]()
Sub masterMacro() Macro1 Macro2 Macro3 End Sub
Another variation on this uses the VBA key word "Call":![]()
Sub masterMacro() Macro1 arg1, arg2, arg3 Macro2 Macro3 End Sub
All of that is fine as long as all macros (plus the "master") are in the same workbook, and the names of the "sub" macros never change. If either of these rules are violated, then you probably want to use the Excel "Run" method instead of the VB Call key word.![]()
Sub masterMacro() Call Macro1(arg1, arg2, arg3) Call Macro2 Call Macro3 End Sub
Note that since you are passing the names of the workbooks and the names of the macros as strings, you can replace the "fixed" strings with variables.![]()
Sub masterMacro() Run "Book1.xls!Macro1", arg1, arg2, arg3 Run "Book2.xls!Macro2" Run "Book3.xls!Macro3" End Sub
![]()
Sub masterMacro() Dim wb1 As String, wb2 As String, wb3 As String Dim mc1 As String, mc2 As String, mc3 As String wb1 = "Book1.xls" mc1 = "Macro1" Run wb1 & mc1, arg1, arg2, arg3 Run "Book2.xls!Macro2" Run "Book3.xls!Macro3" End Sub
Is it possible to call a Private Sub also? How?
Thanks,
Ricky
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks