Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel VBA Macro to Run Other Macros

· 6 min read · Home Tech

In this article
  1. How one VBA macro calls another
  2. Set up the workbook and run the controller
  3. Scope, visibility, and arguments
  4. Calling a macro in another workbook
  5. Choose a call pattern and handle failures
  6. Common problems and safe execution
  7. Frequently Asked Questions

To make an Excel VBA macro run another macro, call its procedure by name—for example, write FormatReport inside the calling procedure. If the target procedure is in another workbook or requires arguments, use an explicitly qualified call such as Application.Run and pass the required values.

How one VBA macro calls another

A macro is usually a Sub procedure in a standard VBA module. A second procedure in the same project can call it directly, provided the target is accessible. This is often the simplest and clearest approach when the order of operations is fixed.

Option Explicit

Public Sub RunReportTasks()
    ' Run the procedures in the required order.
    PrepareData
    FormatReport
    SaveReportCopy
End Sub

Public Sub PrepareData()
    ' Add data-preparation steps here.
End Sub

Public Sub FormatReport()
    ' Add report-formatting steps here.
End Sub

Public Sub SaveReportCopy()
    ' Add save steps here.
End Sub

Place the procedures in a standard module, such as Module1, in the same VBA project. The statements run from top to bottom: Excel finishes PrepareData before it starts FormatReport. A called procedure does not need to be assigned to a worksheet button or run manually first.

Set up the workbook and run the controller

In Excel for Microsoft 365 on Windows, open the Visual Basic Editor with Alt+F11. On a Mac, use Option+F11 or Fn+Option+F11, depending on the keyboard and system settings. In the editor, choose Insert > Module, then add the procedures to that module. Return to Excel and run the controller procedure, RunReportTasks.

  1. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) if it contains VBA code.
  2. Open the VBA editor and insert a standard module.
  3. Paste or write the target procedures and the controller procedure.
  4. Check that each procedure name is spelled consistently and that the code compiles.
  5. Save a copy of the workbook before running the macro, then run the controller from the VBA editor or Excel's macro controls.

Macros cannot be undone with Ctrl+Z, so a backup matters even when the code appears straightforward. Excel for the web can open a macro-enabled workbook, but it cannot create, edit, or run VBA macros; use the desktop app. On Mac, VBA is supported in desktop Excel, though some Windows-specific automation and object features may not be available.

Scope, visibility, and arguments

For a normal direct call, a target procedure should generally be declared Public or have no access modifier (the default is public), and it should be in a standard module. A Private Sub is restricted to its module and cannot normally be called directly from a different module. Procedures in worksheet or ThisWorkbook modules have event-related roles and can be less convenient as general-purpose macros; placing reusable routines in standard modules makes their purpose and scope clearer.

A procedure that needs input can accept arguments. Pass them in parentheses when calling it, or use the Call keyword with parentheses:

Option Explicit

Public Sub BuildMonthlyReport()
    ' Supply the month value to the helper procedure.
    AddMonthHeading "November 2026"
End Sub

Public Sub AddMonthHeading(ByVal monthName As String)
    ' Use the supplied value in the active sheet.
    ActiveSheet.Range("A1").Value = monthName
End Sub

Here the calling procedure supplies a string, and the target receives it through monthName. If a target has required arguments, calling it without them causes an argument-related compile or run-time error. Use named arguments only when the procedure definition supports them, and keep argument types and order consistent.

Calling a macro in another workbook

When a macro lives in a different open workbook, Application.Run can identify the workbook and procedure. The workbook name should include its extension, and names with spaces are safest inside single quotes in the macro reference.

Option Explicit

Public Sub RunExternalReport()
    ' The target workbook must be open and macros must be permitted.
    Application.Run "'Monthly Tools.xlsm'!BuildReport"
End Sub

In this example, Monthly Tools.xlsm must be open and contain a callable procedure named BuildReport. If the procedure takes arguments, supply them after the macro name, separated by commas. For a workbook that may not be open, code must first locate and open it, and should handle errors and close or leave it open deliberately. Do not rely on a workbook's active state to identify the target; explicit names reduce the chance of running the wrong macro.

Application.Run is also useful when the procedure name is chosen at run time or when calling across workbooks. It is not a security bypass: Excel's macro security settings still apply, and external workbooks should be trusted before their code is run.

Choose a call pattern and handle failures

Use a direct call when procedures are in the same VBA project and the workflow is known. It is easier to read, and the VBA editor can check the procedure reference when compiling. Use Application.Run when you need to invoke a procedure by a string name or call a macro in another open workbook. For reusable logic that returns a value, consider a Function rather than a macro-style Sub.

When several tasks run in sequence, decide what should happen if one fails. By default, a run-time error stops execution; later calls will not run. A broad error handler that silently ignores all errors can be worse because it may leave a report partly updated. Handle expected problems specifically, show a useful message, and restore Excel settings if the code changes them.

Option Explicit

Public Sub RunReportSafely()
    On Error GoTo HandleError

    PrepareData
    FormatReport
    Exit Sub

HandleError:
    ' Report the failure rather than continuing with incomplete work.
    MsgBox "The report stopped: " & Err.Description, vbExclamation
End Sub

For longer workflows, a cleanup section can restore settings such as screen updating or calculation mode after an error. Record their original values before changing them, and restore those values rather than assuming a particular default.

Common problems and safe execution

  • “Sub or Function not defined”: Check spelling, whether the target is in the same VBA project, and whether it is private or placed in a restricted module.
  • “Argument not optional”: The target requires one or more inputs; pass values matching its definition.
  • Wrong workbook runs: Qualify the workbook in an Application.Run reference instead of relying on whichever workbook is active.
  • The macro is unavailable: Confirm the file is macro-enabled, the code is in a suitable module, and the workbook's security settings allow trusted macros.
  • Only part of the workflow completes: A prior procedure may have raised an error. Step through the code with F8 in the VBA editor and inspect the failing line.

Macros can edit or delete data, overwrite files, and perform actions that are difficult to reverse. Run code only from a source you trust, review what it does, and make a backup. Do not enable macros merely because a workbook asks you to; follow your organization's security policy.

Frequently Asked Questions

Can one Excel macro run several other macros?
Yes. Put each call on its own line in the required order. Execution proceeds to the next call after the previous procedure returns, unless an error stops the run.

Do the macros have to be in the same module?
No. Public procedures in standard modules within the same VBA project can call one another directly. Keeping related routines in one module can help organization, but it is not required.

Can a macro run another macro with parameters?
Yes. Declare arguments in the target procedure and provide matching values in the call. The types, number, and order of required arguments must agree with the procedure definition.

Can VBA run a macro in a closed workbook?
Not by a simple call alone. The workbook generally needs to be opened first, with appropriate security permission, before its VBA procedure can be invoked. Code that opens it should check the path and handle failures.

Can I run VBA macros in Excel for the web?
No. Excel for the web does not run VBA. Open the macro-enabled workbook in the Excel desktop application to execute its VBA procedures.