我有三个表,它们从SQL数据库中提取数据。
当我从“数据”菜单中单击“全部刷新”时,连接将刷新,但仅表的总和被刷新。
当我右键单击>刷新表本身时,它们反映了正确的信息(告诉我连接确实已刷新)。
我也尝试了ActiveBook.RefreshAll
和以下代码:
Dim wks As Worksheet
Dim qt As QueryTable
For Each wks In Worksheets
For Each qt In wks.QueryTables
qt.Refresh BackgroundQuery:=False
Next qt
Next wks
Set qt = Nothing
如何使用VBA代码刷新表格?
答案 0 :(得分:0)
您应该通过Workbook访问连接。例子
Sub Test()
Dim con As WorkbookConnection
For Each con In ThisWorkbook.Connections
' Your Conditions, for example, check connection name etc.
' If con.Name = "MyConnection" Then
con.Refresh
' Else
' Do your thing
' End if
Next
End Sub