Macro to open 9 workbooks and run anpther macro

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi everyone,
I need a macro to help me automate getting data from one workbook to another .
I have an excellent macro that can copy all the data i want from a workbook to my master workbook once its been opened,
The problem i have isd opening then one at a time and running the macro.

so here what I need.

In Thisworkbook sheet "Run" Range A2:A10 I have a list of the names of the excel workbooks I want to open and copy from
The name is just in the cell like this "Tony Doc" all of them are .xlsm

so all I need is amacro that when run will start at A2 open the workbook, call macro "Copy Data" close workbook go to A3 do the same etc until all 9 have been opened and copied.

Please help if you can

Thanks

Tony
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Adapt to your needs
Amend fPath to the path where the 9 workbooks reside

Code:
Sub OpenWorkBooksAndRunMacro()
    Const fPath = "[COLOR=#ff0000]c:\Folder\Subfolder[/COLOR]"
    Dim wb As Workbook, fName As Range

    For Each fName In ThisWorkbook.Sheets("Run").Range("A2:A10")
        Set wb = Workbooks.Open(fPath & Chr(92) & fName & ".xlsm")
        On Error Resume Next
        Call Copy_Data
        wb.Close False      'amend to TRUE if the workbook should be saved when closed
    Next fName
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,759
Members
449,048
Latest member
excelknuckles

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