Open up workbooks in folder and sub-folders

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,589
Office Version
  1. 2021
Platform
  1. Windows
I have tried to set up code to open up workbooks in a folders C:\extract as well as the sub-folders within C:\extract

I have set up the list of workbooks on sheet "Workspace"

When running the code only one of my workbooks in the sub-foldr open. Hoverver, If I copy the workbooks from the sub-folders into the folder C:\extract , then all the files open


It would be appreciated if someone could amend my code so that the files specified in workspace for eg BR1 ACCNTS (P) , BR2 ACCNTS (P) contained in the subfolder within C:\extract al open

Code:
Sub Open_Test()

 Dim rngCell As Range
    
    
Dim zPATH As String:    zPATH = "C:\extract\"
Dim FSO As Object:      Set FSO = CreateObject("Scripting.FileSystemObject")
Dim FLD As Object:      Set FLD = FSO.GetFolder(zPATH)
Dim SubFLDRS As Object: Set SubFLDRS = FLD.SubFolders
Dim SubFLD As Object

Dim wbData As Workbook


Application.ScreenUpdating = False
 On Error Resume Next
For Each SubFLD In SubFLDRS

  For Each rngCell In Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
    Set wbData = Workbooks.Open(zPATH & SubFLD.Name & "\" & rngCell.Value & ".xls")
    
    
    
    Next rngCell
    Next SubFLD

    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    
    
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,223,099
Messages
6,170,114
Members
452,302
Latest member
TaMere

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