John Carney
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just a quick check - did you need to open them in order? (i.e Week 01 first, then Week 02 etc)
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
- 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
Sid
ASKER
Thanks, Sid. Sorry for the delay.
- John
- John