Run through a folder full of .xls files and copy any sheets matching <name> to a new workbook

gers1978

Board Regular
Joined
Sep 9, 2014
Messages
74
I have a folder with 861 Excel files, each one contains anything from 3 to 30 worksheets. As a task for work, I need to open each one, look for sheets called "ABC" and if found, move them to a new workbook. End result should be a workbook with all the ABC sheets.
Any way of doing this automagically? Thanks
I have Excel 2007 and Windows 7 SP1.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Maybe this...UNTESTED
You'll need to change the file pathe name to suit
Code:
Public Sub MM1()
Dim wbk As Workbook, Filename As String, Path As String
Dim ws As Worksheet, wb As Workbook
Application.ScreenUpdating = False
Set wb = ActiveWorkbook
Path = "C:\Temp\" ' CHANGE TO SUIT
Filename = Dir(Path & "*.xls")
'--------------------------------------------
'OPEN EXCEL FILES
 Do While Len(Filename) > 0  'IF NEXT FILE EXISTS THEN
    Set wbk = Workbooks.Open(Filename:=Path & Filename)
    For Each ws In wbk.Worksheets
            If ws.Name = "ABC" Then 'CHANGE WORKSHEET NAME TO SUIT
            ws.Copy After:=wb.Sheets(ThisWorkbook.Sheets.Count) 'CHANGE COPY RANGE TO SUIT
        End If
    Next ws
    wbk.Close True
    Filename = Dir
Loop
MsgBox " FILES HAVE BEEN PROCESSED"
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,217,440
Messages
6,136,635
Members
450,022
Latest member
Joel1122331

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