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.
 

Some videos you may like

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
19,763
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,842
Messages
5,598,396
Members
414,235
Latest member
sucosama

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
Top