I'm combining a couple hundred workbooks into one book.
I don't need much from each workbook, but I have to go into each one.
Each workbook is in a folder that is named the year that the reports were taken. Those year folders are located in a "Master" folder.
I need to loop through the year folders and hop into each workbook in that folder. I'll grab the info I need and put it in a "Master workbook".
It was suggested in this question that I use this recursive function.
Loop Through All Subfolders Using VBA
I got an invalid outside procedure so I modified my code so that all of it was inside the sub.
The code I have now is a test code that is looking in a test folder I made on my desktop that contains 5 folders. Each of the 5 contains 2 workbooks. It gives me a out of stack space error and it highlights the line DoFolder FileSystem.GetFolder(HostFolder)
.
Here is the code I have so far.
Sub DoFolder(Folder)
Dim FileSystem As Object
Dim HostFolder As String
Application.EnableEvents = False
HostFolder = "C:\Users\27659\Desktop\temp test folder"
Set FileSystem = CreateObject("Scripting.FileSystemObject")
DoFolder FileSystem.GetFolder(HostFolder)
Dim i As Long
Dim wb As Workbook
Dim ws As Worksheet
Set wb = Application.Workbooks("\\drive name\public\Organizational Development\my name\Open Projects\Project 1 Milling Improvements\Past Data\Past Data Collection and Summary Book Start 10_29_2018.xlsm")
Set ws = wb("Sheet1")
i = 9
Dim SubFolder
For Each SubFolder In Folder.SubFolders
DoFolder SubFolder
Next
Dim File
For Each File In Folder.Files
Folder.Files.Open
wb.ws.Cells(i, 2).Value = ActiveWorkbook.Worksheets(1).Cells(1, 1).Value
i = i + 1
Next
Application.EnableEvents = True
End Sub