【发布时间】:2017-03-23 08:58:37
【问题描述】:
我正在刷新 Access 上的查询并循环遍历表,但循环超出了刷新 - 所以我没有得到正确的最后一行。
刷新后,a 应该等于 2746,但它返回 1478,这是刷新前的最后一行。
vPath = ThisWorkbook.Sheets(vHome).Range("LogTblFolder")
vFile = ThisWorkbook.Sheets(vHome).Range("LogTblFile")
Set wb = Workbooks.Open(vPath & vFile)
Sheets("Main").Select
ActiveWorkbook.Connections("CTA_DB_Full3").Refresh
ActiveWorkbook.Connections("CTA_DB_Full3").Refresh
Call WaitForRefresh(1)
a = 1:Do Until Sheets("Main").Cells(a, 1).Value2 = "":a = a + 1:Loop
vArray = Sheets("Main").Range(Cells(2, 1), Cells(a, 94))
wb.Close False
Public Function WaitForRefresh(intSeconds As Integer)
Dim dblStart As Double
If intSeconds > 0 Then
dblStart = Timer()
Do While Timer < dblStart + intSeconds
Loop
End If
End Function`
非常感谢您的帮助!!!
【问题讨论】:
-
我认为如果你关闭 run as background query ,你的代码自然会等待
-
另外,你可以把
databodyrange从listobject放到一个数组中
标签: excel vba ms-access row refresh