With the help of Cor_Blimey's post.. (Loop Through All Subfolders Using VBA)
This will loop through all subfolders and subfolders in the subfolders (in theory indefinitely)..
Public Sub NonRecursiveMethod()
Dim fso, oFolder, oSubfolder, oFile, queue As Collection
Dim FoundFolder as Boolean
Set fso = CreateObject("Scripting.FileSystemObject")
Set queue = New Collection
queue.Add fso.GetFolder("C:\Atul\Data")
Do While queue.Count > 0
Set oFolder = queue(1)
queue.Remove 1 'dequeue
For Each oSubfolder In oFolder.SubFolders
queue.Add oSubfolder
If oSubfolder Like "*" & ThisWorkbook.Name & "*" Then 'Replace workbook name if necessary
Workbooks.Open Filename:=oSubfolder & "\report.xls"
FoundFolder = True
Exit For
End If
Next oSubfolder
Loop
If FoundFolder = False Then MsgBox "Error: Folder '" & ThisWorkbook.Name & "' could not be found", vbExclamation, "Error"
End Sub
Alternatively, you can look in the subfolders from just the main folder
Sub SubFoldersinMainFolder()
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder("C:\Atul\Data")
Set subfolders = folder.subfolders
For Each subfolders In subfolders
If subfolders Like "*" & ThisWorkbook.Name & "*" Then 'Replace workbook name if necessary
Workbooks.Open Filename:= subfolders & "\report.xls"
FoundFolder = True
Exit For
End If
Next subfolders
If FoundFolder = False Then MsgBox "Error: Folder '" & ThisWorkbook.Name & "' could not be found", vbExclamation, "Error"
End Sub
I must add that the word "folder" begins to look very weird now