我无法在不使Excel崩溃的情况下运行具有多个查询连接刷新的宏。
Sub Refresh()
Application.EnableEvents = False
Application.ScreenUpdating = False
With Sheets("DB")
.Visible = -1
.Unprotect Password:="kali1220"
End With
With Sheets("LIVRAISON")
.Select
.Unprotect Password:="kali1220"
End With
'Actualisation des données
ActiveWorkbook.Connections("Query - qGenius").Refresh
Application.CalculateUntilAsyncQueriesDone
ActiveWorkbook.Connections("Query - qDB").Refresh
Application.CalculateUntilAsyncQueriesDone
AdjustLayout
With Sheets("LIVRAISON")
.Select
.Protect Password:="", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFiltering:=True
End With
With Sheets("DB")
.Visible = 2
.Protect Password:="", DrawingObjects:=True, Contents:=True, Scenarios:=True
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
如果我逐步运行宏,它总是可以正常工作,并且我完成了多个其他看起来相同的宏而没有问题。在这种情况下,唯一的区别是qDB是对qGenius的查询。我不知道这是否会影响宏,如果这样会解决。
qGenius是SQL服务器上的查询