How to Run Macro from other VBA projects?

How to Run Macro from other VBA projects?

Application.Run

There are cases where developer may want to execute code from other project which is kept with open file or somewhere in Windows. In this article we will show how you can call a macro stored in another project.

Syntax

Application.Run MacroName:=”Project.ModuleName.ProcedureName”

Code example

Application.Run: Runs a macro or calls a function. This can be used to run a macro written in Visual Basic or the Microsoft Excel macro language, or to run a function in a DLL or XLL. This is a method which takes 31 arguments the very first argument is macro name which is mandatory remaining can be passed as additional parameter if your procedure or function takes arguments.

MacroName: takes complete path of the macro having following segments:

  1. Project: this is a constant which will refer all available projects within open environment
  2. ModuleName: the name of module where code is written
  3. ProcedureName: name of the code block which needs to be executed

Below screenshot shows two projects in one file “NewMacro” and “Module1“. “Module1” contains “test” procedure and NewMacro contains Application.Run method to call “test” method:

Test method

Output

Please leave your comments or queries under comment section also please do subscribe to out blogs to keep your self upto date.

Leave a Reply

Your email address will not be published.