循环导致excel冻结?
问题描述:
我试图从各个变量的集合中复制内容,并将其冻结每次它运行的第一个文件循环导致excel冻结?
RecursiveDir colFiles, path, "*.xlsm", True
For Each varFile In colFiles
lineCount = 0
reportRow = 3
Set reportBook = Workbooks.Open(varFile)
Set cooSummary = reportBook.Sheets("Audit")
Do While cooSummary.Cells(reportRow, 1) <> ""
lineCount = lineCount + 1
Loop
lineNum = lineNum + 1
With cooSummary
scanDate = FileDateTime(varFile)
scanned = lineCount
auditor = .Cells(1, 2)
End With
ReDim Preserve reportArray(3, lineNum)
reportArray(0, lineNum) = scanDate
reportArray(1, lineNum) = scanned
reportArray(2, lineNum) = auditor
reportRow = reportRow + 1
reportBook.Close SaveChanges:=False
Next varFile
答
您需要增加在做循环reportRow
,否则将无法完成。
Do While cooSummary.Cells(reportRow, 1) <> ""
lineCount = lineCount + 1
reportRow = reportRow + 1
Loop
+0
谢谢。我的添加错过了这些东西> _
+0
np,如果它解决它,请接受答案:) –
您不在循环内增加reportRow,您正在增加linecount,因此如果cell(3,1)不为空,do循环将永远不会结束。 –