2016-11-30 170 views
1

我試圖從各個變量的集合中複製內容,並將其凍結每次它運行的第一個文件循環導致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 
+2

您不在循環內增加reportRow,您正在增加linecount,因此如果cell(3,1)不爲空,do循環將永遠不會結束。 –

回答

2

您需要增加在做循環reportRow,否則將無法完成。

Do While cooSummary.Cells(reportRow, 1) <> "" 
    lineCount = lineCount + 1 
    reportRow = reportRow + 1 
Loop 
+0

謝謝。我的添加錯過了這些東西> _ < –

+0

np,如果它解決它,請接受答案:) –