1
我正在刷新Access上的查询并循环遍历表,但循环超出了刷新 - 所以我没有得到正确的最后一行。Excel/Access VBA - 无法获取上次使用的行,因为查询刷新
刷新后,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`
帮助深表感谢!
我觉得如果你关闭运行的后台查询,您的代码将自然等待 –
另外,你可以把'databodyrange'从'listobject'到一个数组 –