VBA learner ITG
Active Member
- Joined
- Apr 18, 2017
- Messages
- 272
- Office Version
- 365
- Platform
- Windows
- MacOS
Hi Experts,
I need your guidance. I have the below code whoch was written to cycle through all files in a folder.
Now im faced with a challenge of having multiple sub folders upon sub folder within the parent folder.
Is it possible to adapt this code to loop through Parent folder and its sub folders and perform its task.
I need your guidance. I have the below code whoch was written to cycle through all files in a folder.
Now im faced with a challenge of having multiple sub folders upon sub folder within the parent folder.
Is it possible to adapt this code to loop through Parent folder and its sub folders and perform its task.
Code:
Sub RunAll()
Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As fileDialog
''///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) & Application.PathSeparator
End With
Application.ScreenUpdating = False
''///In Case of Cancel
NextCode:
myPath = myPath
If myPath = "" Then Exit Sub
''///Target File Extension (must include wildcard "*")
myExtension = "*.xls*"
''///Target Path with Ending Extension
myFile = Dir(myPath)
Call LoopExcelFiles(myPath, "*.xls*")
MsgBox iCnt & " files processed"
For Each wb In Workbooks
If wb.Name <> ThisWorkbook.Name Then wb.Close True
Next wb
Application.ScreenUpdating = True
End Sub