Link to home
Start Free TrialLog in
Avatar of John Carney
John CarneyFlag for United States of America

asked on

Macro that opens sequentially named workbooks and runs the same routine on each one

Basically, the folder  "H:\...\SourceFiles\" contains an expanding list of files with names like:

2011 Week 01.xls
2011 Week 02.xls, etc.

I want to open them one at a time and run the routine below on them. How do I do that? There might be other files in the folder that don't end with "Week ##.xls", so it would be important to have the file selection based on the common ending for each file.

Thanks,
John
Sub Aggregate()
Application.ScreenUpdating = False

Workbooks.Open Filename:= _
 "H:\Depts\css\A_ILS & Reliability\Reliability\1-CURRENT\System Reporting\SDAE\JAL\3_Working Files\SourceFiles\JAL SourceFile 2011 Week 01.xls"
 Dim top As Range, btm As Range, rng As Range
 Set top = [A6]
 Set btm = top.End(xlDown)
 Set rng = Range(top, btm).EntireRow

 rng.Copy
 ThisWorkbook.Activate
 Dim top2 As Range
 Set top2 = [A4].End(xlDown).Offset(1, 0)
 top2.PasteSpecial Paste:=xlPasteValues
 Application.CutCopyMode = False
 ActiveWindow.ActivateNext
 ActiveWorkbook.Close
 
Application.ScreenUpdating = True
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of SiddharthRout
SiddharthRout
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rory Archibald
Just a quick check - did you need to open them in order? (i.e Week 01 first, then Week 02 etc)
Avatar of John Carney

ASKER

Hi Sid and Rory, thanks for posting. I can try this out at work tomorrow. I don't think the weeks have to be in order, I'm not sure.

- John
The code I gave doesn't open the file in sequential order. As far as I could understand from your query, it's ok if the files are opened in any order?

Sid
Thanks, Sid. Sorry for the delay.

- John