[英]Refresh power query VBA
所以我使用下面的代码来刷新我的查询连接,但是,如果由于 wtv 原因导致刷新失败,我该如何显示消息? 因为这个 VBA 显示我刷新完成,即使我的查询有多个错误。
'Worksheets("Details").Unprotect
Dim Connection As WorkbookConnection
Dim bugfix As Integer
For bugfix = 1 To 2
On Error Resume Next
For Each Connection In ActiveWorkbook.Connections
With Connection
If (.Type = xlConnectionTypeODBC) Then
.ODBCConnection.BackgroundQuery = False
Else
If (.Type = xlConnectionTypeOLEDB) Then
.OLEDBConnection.BackgroundQuery = False
End If
End If
End With
Connection.Refresh
Next Connection
Next bugfix
'Worksheets("Details").Protect , AllowFiltering:=True, AllowFormattingCells:=True, DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingColumns:=True
MsgBox "Refresh Complete"
End Sub
相信它会停止在Connection.Refresh
- 使用调试器。 如果你想在你的 Sub 中捕获这个错误,你需要定义类似On Error Goto MyError
的东西,然后用消息或其他东西处理错误。 Resume Next
将在错误的下一行继续您的代码。
Exit Sub
MyError:
MsgBox (Err.Description)
resume next
End Sub
此处描述于: Microsoft Learn
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.