Macro - Copy all worksheets in C:\Test & Paste 2 New Wb

MikeL

Active Member
Joined
Mar 17, 2002
Messages
440
Hi,

I have about 20 .XLS workbooks in the folder C:\Test each with varying degree of worksheets in them (typically 2 to 5 sheets).

Can VBA be executed to copy all sheets in the workbooks and paste them all into a New Workbook?

Thanks in advance,
Mike
 

Some videos you may like

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,219
Office Version
  1. 365
Platform
  1. Windows
Yes.

Perhaps something like this:
Code:
Dim I As Integer
Dim wbDest As Workbook
Dim wbSource As Workbook
Dim ws As Worksheet
    
    Application.ScreenUpdating = False

    Set wbDest = ThisWorkbook
    ' or alternativwly Set wbDest = Workbooks.Add

     With Application.FileSearch
        .NewSearch
        .LookIn = "C:\TEST"
        .FileType = msoFileTypeExcelWorkbooks
        .Execute
        
        For I = 1 To .FoundFiles.Count
        
            Set wbSource = Workbooks.Open(.FoundFiles(I))
            
            For Each ws In wbSource.Worksheets
                
                ws.Copy After:=wbDest.Worksheets(wbDest.Worksheets.Count)
                
            Next ws
            
            wbSource.Close
        Next I
    End With
    Application.ScreenUpdating = True
 

Watch MrExcel Video

Forum statistics

Threads
1,123,057
Messages
5,599,550
Members
414,316
Latest member
ExcelLee

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