Hi,
I hope someone can help.
I am trying to create a command within a master document that will loop through a folder and extract values from specific cells and paste them to the master document. The folder has hundreds of individual files, all named differently, and each file has multiple worksheets but all worksheets are in the same format so cell references are uniform. I have managed to create something which I think should work but unfortunately I have been getting the Run-time error 5 at the point where the information is to be transferred:
If anyone has any ideas that might help I'd be very grateful.
Thanks
I hope someone can help.
I am trying to create a command within a master document that will loop through a folder and extract values from specific cells and paste them to the master document. The folder has hundreds of individual files, all named differently, and each file has multiple worksheets but all worksheets are in the same format so cell references are uniform. I have managed to create something which I think should work but unfortunately I have been getting the Run-time error 5 at the point where the information is to be transferred:
VBA Code:
Sub LoopThroughLogs()
Dim wb As Workbook, ws As Worksheet
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder("T:\ThinkTank\CENTRAL FILES\LOGS\RETURNED LOGS\")
y = ThisWorkbook.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1
For Each wbFile In fldr.Files
y = ThisWorkbook.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1
If fso.GetExtensionName(wbFile.Name) = "xls" Then
Set wb = Workbooks.Open(wbFile.Path)
For Each ws In wb.Sheets
ThisWorkbook.Sheets("Sheet1").Cells(y, 2) = ws.Cells("F4") '''HERE IS WHERE THE RUN-TIME ERROR INTERUPTS THE COMMAND
ThisWorkbook.Sheets("Sheet1").Cells(y, 3) = ws.Cells("F6")
ThisWorkbook.Sheets("Sheet1").Cells(y, 4) = ws.Cells("B11")
ThisWorkbook.Sheets("Sheet1").Cells(y, 5) = ws.Cells("I11")
y = y + 1
Next ws
wb.Close
End If
Next wbFile
End Sub
If anyone has any ideas that might help I'd be very grateful.
Thanks