Run macro from another workbooks

Dokat

Active Member
Joined
Jan 19, 2015
Messages
304
Office Version
  1. 365
Hi,

I have a workbook that I'd like to a run code that needs to trigger codes in other two workbooks..
Below is the code i am using. First two lines are to trigger codes in other two workbooks. The name of the code in those workbooks is Run under Summary sheet. Under the In each workbook Run Macro calls for other Macro's to run.

Below code is under thisworkbook module. When I run the code below it returns Run Time Error 1004.. I can run the codes without any issues by opening each workbook however I am not able to right from the active workbook.. What may cause this problem? Is below code not correct?



VBA Code:
Sub RunAll()

Application.Run "'C:\Users\dokat\OneDrive - BIC\BIC\Power BI\Trade Report\Upload Data\2017-2022 6 Year Trended PnL by L3 - YTD.xlsm'!Summary.Run"
Application.Run "'C:\Users\dokat\OneDrive - BIC\BIC\Power BI\Trade Report\Upload Data\2017-2022 6 Year Trended PnL by L3 - Month.xlsm'!Summary.Run"
Call CopyPasteMTDYTD

End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi Dokat,
Are the two listed workbooks open at the time of trying to run them from the third workbook? if not you might need to open them first. Can include this in your macro to open the two other files..
 
Upvote 0
Hi Dokat,
Are the two listed workbooks open at the time of trying to run them from the third workbook? if not you might need to open them first. Can include this in your macro to open the two other files..
No they are not. They are closed at the time of running the code.
 
Upvote 0
Hi Dokat,
Best try adding some code to open the other workbooks prior to trying to access their macros. You can then close them again after if you don't need them any more. Excel can only execute open code.
I have one workbook that contains all of my macros. It's opened as an add in so they are always available.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top