There are a few different ways that you can run a macro in a number of workbooks in Excel. One way is to use the Application.Run method. This method will allow you to run a macro in another workbook, provided that the workbook is open. For example, let's say that you have a macro called "MyMacro" in a workbook called "MyWorkbook.xlsm". You can run this macro from any other open workbook by using the following code:
Application.Run "MyWorkbook.xlsm!MyMacro"
Another way to run a macro in another workbook is to use the Workbooks.Open method. This method will open the specified workbook and then run the macro. For example, let's say that you have a macro called "MyMacro" in a workbook called "MyWorkbook.xlsm". You can run this macro from any other open workbook by using the following code:
Workbooks.Open Filename:="C:\MyWorkbooks\MyWorkbook.xlsm"
Application.Run "MyMacro"
ActiveWorkbook.Close SaveChanges:=False
If you want to run a macro in all open workbooks, you can use the For Each loop. For example, let's say that you have a macro called "MyMacro" and you want to run this macro in all open workbooks. You can use the following code:
For Each wb In Workbooks
Application.Run "MyMacro"
Next wb