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

MikeL

Active Member
Joined
Mar 17, 2002
Messages
488
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
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
 
Upvote 0
thanks!

Works great! Thank you very much Norie.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,598
Members
449,089
Latest member
Motoracer88

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