[font=Verdana][color=darkblue]Option[/color] [color=darkblue]Explicit[/color]
[color=darkblue]Sub[/color] test()
[color=darkblue]Dim[/color] objFSO [color=darkblue]As[/color] [color=darkblue]Object[/color]
[color=darkblue]Dim[/color] objFolder [color=darkblue]As[/color] [color=darkblue]Object[/color]
[color=darkblue]Dim[/color] wkb [color=darkblue]As[/color] Workbook
[color=darkblue]Dim[/color] strArray() [color=darkblue]As[/color] [color=darkblue]String[/color]
[color=darkblue]Dim[/color] strTemp1 [color=darkblue]As[/color] [color=darkblue]String[/color]
[color=darkblue]Dim[/color] strTemp2 [color=darkblue]As[/color] [color=darkblue]String[/color]
[color=darkblue]Dim[/color] Cnt [color=darkblue]As[/color] [color=darkblue]Long[/color]
[color=darkblue]Dim[/color] j [color=darkblue]As[/color] [color=darkblue]Long[/color]
[color=darkblue]Dim[/color] k [color=darkblue]As[/color] [color=darkblue]Long[/color]
[color=darkblue]Set[/color] objFSO = CreateObject("Scripting.FileSystem[color=darkblue]Object[/color]")
[color=darkblue]Set[/color] objFolder = objFSO.GetFolder("C:\Users\Domenic\Desktop") [color=green]'change the path to the main folder, accordingly[/color]
Cnt = 0
[color=darkblue]Call[/color] recurseSubFolders(objFolder, strArray(), Cnt)
[color=green]'Sort array[/color]
[color=darkblue]For[/color] j = 1 [color=darkblue]To[/color] Cnt - 1
[color=darkblue]For[/color] k = j + 1 [color=darkblue]To[/color] Cnt
[color=darkblue]If[/color] strArray(2, j) > strArray(2, k) [color=darkblue]Then[/color]
strTemp1 = strArray(1, k)
strTemp2 = strArray(2, k)
strArray(1, k) = strArray(1, j)
strArray(2, k) = strArray(2, j)
strArray(1, j) = strTemp1
strArray(2, j) = strTemp2
[color=darkblue]End[/color] [color=darkblue]If[/color]
[color=darkblue]Next[/color] k
[color=darkblue]Next[/color] j
[color=green]'Open each file[/color]
[color=darkblue]For[/color] j = 1 [color=darkblue]To[/color] Cnt
[color=darkblue]Set[/color] wkb = Workbooks.Open(strArray(1, j))
[color=green]'Your code here to do stuff[/color]
wkb.Close savechanges:=[color=darkblue]False[/color]
[color=darkblue]Next[/color] j
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] recurseSubFolders([color=darkblue]ByRef[/color] Folder [color=darkblue]As[/color] [color=darkblue]Object[/color], [color=darkblue]ByRef[/color] Arr() [color=darkblue]As[/color] [color=darkblue]String[/color], [color=darkblue]ByRef[/color] i [color=darkblue]As[/color] [color=darkblue]Long[/color])
[color=darkblue]Dim[/color] SubFolder [color=darkblue]As[/color] Object
[color=darkblue]Dim[/color] strName [color=darkblue]As[/color] [color=darkblue]String[/color]
[color=darkblue]For[/color] [color=darkblue]Each[/color] SubFolder [color=darkblue]In[/color] Folder.SubFolders
[color=darkblue]Let[/color] strName = Dir$(SubFolder.Path & "\" & "*.xlsx")
[color=darkblue]Do[/color] [color=darkblue]While[/color] strName <> vbNullString
[color=darkblue]Let[/color] i = i + 1
[color=darkblue]ReDim[/color] [color=darkblue]Preserve[/color] Arr(1 [color=darkblue]To[/color] 2, 1 To i)
[color=darkblue]Let[/color] Arr(1, i) = [color=darkblue]Sub[/color]Folder.Path & "\" & strName
[color=darkblue]Let[/color] Arr(2, i) = strName
[color=darkblue]Let[/color] strName = Dir$()
[color=darkblue]Loop[/color]
[color=darkblue]Call[/color] recurseSubFolders(SubFolder, Arr(), i)
[color=darkblue]Next[/color]
[color=darkblue]End[/color] Sub
[/font]