Im having trouble getting all files returned from my code. I have a large amount of files in subfolders of a directory that I need to copy information from certain cells, how would I get the code to return all .xlsx in the folder plus the subfolders?
Sub Copy_Values_From_Workbooks()
Dim matchWorkbooks As String
Dim destSheet As Worksheet, r As Long
Dim folderPath As String
Dim wbFileName As String
Dim fromWorkbook As Workbook
'Folder path and wildcard workbook files to import cells from
matchWorkbookCs = "D:\Data\Analysis\Service\records\Templates\*.xlsx"
'Define destination sheet
Set destSheet = ActiveWorkbook.Worksheets("Report")
r = 0
Application.ScreenUpdating = False
folderPath = Left(matchWorkbooks, InStrRev(matchWorkbooks, "\"))
wbFileName = Dir(matchWorkbooks)
While wbFileName <> vbNullString
Set fromWorkbook = Workbooks.Open(folderPath & wbFileName)
With fromWorkbook.Worksheets("Dashboard")
destSheet.Range("A2").Offset(r).Value = .Range("C5").Value
destSheet.Range("B2").Offset(r).Value = .Range("C3").Value
destSheet.Range("C2").Offset(r).Value = .Range("D51").Value
destSheet.Range("D2:E2").Offset(r).Value = .Range("D56:E56").Value
r = r + 1
End With
fromWorkbook.Close savechanges:=False
DoEvents
wbFileName = Dir
Wend
Application.ScreenUpdating = True
MsgBox "Finished"
End Sub