I have research this question and found some VBA code that works if one folder is selected that has the excel files contained in it. If I try to drill down through multiple folders and subfolders, the code quits and indicates through the message box that it has finished when it really hasn't. Here is the code that I copied from another source that processes the excel files in one folder, but doesn't allow me to drill down through multiple subfolders to get to it.
I thought that the Application.GetOpenFolderName would work instead of FolderDialogPicker, but it doesn't seem to allow the selection.
Any assistance would be appreciated.
Thanks
Code:
Sub LoopAllExcelFilesInFolder()
Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As FileDialog
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
'Retrieve Target Folder Path From User
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Select A Target Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
myPath = .SelectedItems(1) & "\"
End With
NextCode:
myPath = myPath
If myPath = "" Then GoTo ResetSettings
myExtension = "*.xls*"
myFile = Dir(myPath & myExtension)
Do While myFile <> ""
Set wb = Workbooks.Open(Filename:=myPath & myFile)
DoEvents
'Sample execution code [Change First Worksheet's Background Fill Blue]
‘wb.Worksheets(1).Range("A1:Z1").Interior.Color = RGB(51, 98, 174)
wb.Close SaveChanges:=True
DoEvents
myFile = Dir
Loop
MsgBox "Task Complete!"
ResetSettings:
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Any assistance would be appreciated.
Thanks