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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
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,214,918
Messages
6,122,243
Members
449,075
Latest member
staticfluids

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