Possible Duplicate:
get list of subdirs in vba
I'm trying to apply the following code, which applies to running this VBA loop through all files in a folder, to make it run through all folders within one folder.
Is there any way that this is possible?
I have about 50 folders, each with the same named workbook, so I'd need to try and make it more efficient.
Thanks!
Sub LoopFiles()
Application.DisplayAlerts = False
Dim strDir As String, strFileName As String
Dim wbCopyBook As Workbook
Dim wbNewBook As Workbook
strDir = "C:\Documents and Settings\mburke\Desktop\Occupancy 2013\"
strFileName = Dir(strDir & "*.xlsm")
Set wbNewBook = Workbooks.Add
Do While strFileName <> ""
Set wbCopyBook = Workbooks.Open(strDir & strFileName)
wbCopyBook.Sheets(1).Copy Before:=wbNewBook.Sheets(1)
wbCopyBook.Close False
strFileName = Dir
Loop
Application.DisplayAlerts = True
End Sub