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` 

帮助非常感谢!

这可能是一个开始

 Sub x() Dim l As ListObject Set l = ActiveSheet.ListObjects(1) l.QueryTable.BackgroundQuery = False Debug.Print l.ListRows.Count l.Refresh Debug.Print l.ListRows.Count varray = l.DataBodyRange.Value End Sub