到目前爲止,您一次輸出所有recordsets
內容,這比每(至少對於大型記錄集)中的每field
循環更快。
如果你想真正循環,那就將是這樣的(凌亂和未經測試):
Dim i As Integer, j as Integer
Dim fld As Object
' print headers, starting from A4 to the left
i = 1
j = 4
For Each fld In .Fields
ThisWorkbook.Sheets(mySheet).Cells(j, i).Value = fld.Name
i = i + 1
Next fld
' print record by record, field by field
i = 1
j = j + 1
While Not .EOF
For Each fld In .Fields
ThisWorkbook.Sheets(mySheet).Cells(j, i).Value = fld.Value
' here you could test for something like
' If fld.Name = "change" and fld.Value = "X" Then ThisWorkbook.Sheets(mySheet).Cells(j, i).Interior.Color = vbYellow
i = i + 1
Next fld
j = j + 1
.MoveNext
Wend
這可以簡化相當多一些,但一般來說,你將不得不使用記錄的嵌套循環以及每條記錄中的字段。對於你想做的事情,這可能太笨拙了。
較爲合理的做法是使用一些簡單的像
只是格式化你的細胞,獨立於你已經處理過的記錄的,或添加條件格式表示的範圍(使用VBA),它具有更新本身的優勢
爲我工作。謝謝。 –