Macro to open other Excel files, run a specific Macro, and close?

Bret1

Board Regular
Joined
Jun 14, 2013
Messages
199
I have multiple Excel worksheets that I open daily, run a Macro that pulls specific data and automatically saves with today's date. I would like to simply my efforts. Is it possible to create a Macro in a new worksheet that I can set to open other specific worksheets (in separate folders), run a specific Macro that is saved in that worksheet, close the file after Macro completes, then open next worksheet listed?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Something along these lines should work. I don't quite understand the specifics of what you want to do
Pathname is the string of the file path of the workbook to be opened
RunSub is the name of the macro in that workbook
VBA Code:
Sub OpenWorkbooksAndRunMacros()
    
    Workbooks.Open PATHNAME
    RunSub
    Workbooks.Close PATHNAME
    

End Sub
 
Upvote 0
Solution
Something along these lines should work. I don't quite understand the specifics of what you want to do
Pathname is the string of the file path of the workbook to be opened
RunSub is the name of the macro in that workbook
VBA Code:
Sub OpenWorkbooksAndRunMacros()
   
    Workbooks.Open PATHNAME
    RunSub
    Workbooks.Close PATHNAME
   

End Sub
Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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