Sunday, 27 September 2015

How to Call and Run a Macro from Another Workbook

How to Run a Macro from Another Workbook
When we want to run a Macro from an event or from another Macro in the same Workbook , We can call the Macro like this in code :

Call MyMacroName

But if we want to run a macro that is in another workbook or Add-In(File or add-in must be open).
We can use Application.Run as follows :

Application.Run "MyWorkBook.xls!MyMacroName"

Case I : Suppose if the Workbook name is not known in advance and its dynamically declared in a variable then we call the Macro as follows :


Application.Run " '" & strFileName & "'!MyMacroName"

Case II :Suppose if the Macro is specific to particular Worksheet Event , then we need to specify the Sheet name along with Macro name as follows :

Application.Run " '" & strFileName & "'!Sheet1.MyMacroName"

Please Note :
To get the Exact Macro name , we need to go to Macros in Excel Workbook where we can see all the Macros with Correct names to be use as reference for Calling/Running.

Thanks,
TAMATAM

No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts