Importing worksheets from files stored in a folder

alekos7

New Member
Joined
Feb 16, 2017
Messages
5
Hello!

I'm trying to import all worksheets from all files stored a folder named "Path Folder" into an active workbook.

Example

I have 3 workbooks named Project 1, Project 2 and Project 3 in the folder named "Path Folder" and each workbook contains two sheets.
I need to pull all 6 sheets into my active workbook named "Master".

I've tried a couple different things and they aren't working. Thanks for your help!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
What type of files are they? .xlsx, .xls, etc? This code imports all worksheets from all the .xlsx files in a folder:

Code:
Public Sub Import_All_Worksheets_From_All_Workbooks_In_Folder()

    Dim folderPath As String, fileName As String
    Dim destinationWorkbook As Workbook, sourceWorkbook As Workbook
    Dim ws As Worksheet

    Set destinationWorkbook = ActiveWorkbook
    
    folderPath = "C:\Path Folder\"   'CHANGE THIS TO SUIT
        
    folderPath = Trim(folderPath)
    If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
    
    Application.ScreenUpdating = False

    fileName = Dir(folderPath & "*.xlsx")
    While fileName <> vbNullString
        Set sourceWorkbook = Workbooks.Open(folderPath & fileName)
        For Each ws In sourceWorkbook.Worksheets
            With destinationWorkbook
                ws.Copy After:=.Worksheets(.Worksheets.Count)
                '.Worksheets(.Worksheets.Count).Name = .Worksheets(.Worksheets.Count).Name & " " & .Worksheets.Count
            End With
        Next
        sourceWorkbook.Close savechanges:=False
        fileName = Dir
    Wend
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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