Hello, I need some help getting specific cell information into my report worksheet from all excel files in the folder and all subfolders. I have managed to get the code to open all the files in the directory but whenever I try to extract the cell information I get an error.
I am wanting it to run through each file, bring in information from multiple cells in all the files to create a report.
I am wanting it to run through each file, bring in information from multiple cells in all the files to create a report.
VBA Code:
Sub copydata()
Call GetFiles("D:\data\Rev\Analysis\records\files\")
End Sub
Sub GetFiles(ByVal path As String)
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim folder As Object
Set folder = fso.GetFolder(path)
Dim subfolder As Object
Dim file As Object
For Each subfolder In folder.SubFolders
GetFiles (subfolder.path)
Next subfolder
Application.ScreenUpdating = False
For Each file In folder.Files
Workbooks.Open (file)
Range("A2").Offset(r).Value = .Range("C5").Value
Range("B2").Offset(r).Value = .Range("D51").Value
Workbooks.Close (file)
Next file
Set fso = Nothing
Set folder = Nothing
Set subfolder = Nothing
Set file = Nothing
End Sub