Code: Select all
Do While myFile <> "" Or myFile <> "Template.xlsx"
Code: Select all
Sub LoopAllExcelFilesInFolder()
Dim wb As Workbook
Dim wsSrc As Worksheet: Set wsSrc = ActiveWorkbook.Sheets(1)
Dim myPath As String
Dim myFile As String
Dim strFile As String
Dim Path As String
Dim myMaster As String
Dim r As Long: r = 1
myPath = ActiveWorkbook.Path & Application.PathSeparator
strFile = "*.xlsx"
myFile = Dir(myPath & strFile)
Do While myFile <> "" Or myFile <> "Template.xlsx"
Set wb = Workbooks.Open(Filename:=myPath & myFile)
DoEvents
r = r + 1
wsSrc.Cells(r, 2) = myFile
wsSrc.Cells(r, 3) = wb.Sheets(1).Range("M2")
wsSrc.Cells(r, 4) = wb.Sheets(1).Range("M17")
wb.Close SaveChanges:=True
DoEvents
myFile = Dir
Loop
End Sub