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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,223,104
Messages
6,170,125
Members
452,303
Latest member
c4cstore

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