我的代码只返回一个文件数据,但不返回整个集合。
'Collect all data from audit templates
RecursiveDir colFiles, path, "*.xlsm", True
For Each varFile In colFiles
Set reportBook = Workbooks.Open(varFile)
Set suSummary = reportBook.Sheets("SU Summaries")
Do While suSummary.Cells(reportRow, 1) <> "" 'Only report if there are scanned files
lineNum = lineNum + 1
With suSummary
scanDate = FileDateTime(varFile)
scanned = .Cells(reportRow, 2)
auditor = .Cells(reportRow, 3)
End With
ReDim Preserve reportArray(3, lineNum)
reportArray(0, lineNum) = scanDate
reportArray(1, lineNum) = scanned
reportArray(2, lineNum) = auditor
reportRow = reportRow + 1
Loop
reportBook.Close SaveChanges:=False
Next varFile
'Paste data into Scan Sheet
For lineNum = 1 To UBound(reportArray, 2)
With scanSheet
.Cells(baseRow, 1) = reportArray(0, lineNum) 'Date Scanned
.Cells(baseRow, 2) = reportArray(1, lineNum) 'Scanned
.Cells(baseRow, 3) = reportArray(2, lineNum) 'Auditor
.Cells(baseRow, 4).Formula = "=IF(LEN(C" & baseRow & ")>2,TRIM(LEFT(TRIM(C" & baseRow & "),2)),C" & baseRow & ")" 'Auditor1
.Cells(baseRow, 5).Formula = "=IF(LEN(C" & baseRow & ")>2,TRIM(RIGHT(TRIM(C" & baseRow & "),2)),C" & baseRow & ")" 'Auditor 2
.Cells(baseRow, 6).Formula = "=B" & baseRow & "/2" 'Average Scanned
.Cells(baseRow, 7).Formula = "=IF(OR(ISNA(VLOOKUP(D" & baseRow & ",Summary!A:C,1,0)),ISNA(VLOOKUP(E" & baseRow & ",Summary!A:C,1,0))),""MISSING"",""GOOD"")" 'Auditor CK
End With
baseRow = baseRow + 1
Next lineNum
宏运行正常并打开所有工作簿,但它只会粘贴第一个工作簿中的数据而不是所有工作簿。