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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,313
Office Version
  1. 365
  2. 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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,038
Messages
5,856,980
Members
431,843
Latest member
Malahhai

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