我试图从我的工作簿中删除连接,但我仍然发现运行时错误5.我不知道该怎么做,因为在我的其他项目中它的工作原理.
谢谢你的建议.来自捷克共和国的问候.
Sub refresh_all()
Dim i As Integer
'~~> refresh workbook query
Application.DisplayAlerts = False
Workbooks("UAC_report_p.xlsb").Activate
'~~> wait for refresh then execute Call save_as
Do Until Application.CalculationState = xlDone
DoEvents
Loop
ActiveWorkbook.RefreshAll
Workbooks("UAC_report_p.xlsb").Activate
'~~>kill all connections
For i = 1 To ActiveWorkbook.Connections.Count
If ActiveWorkbook.Connections.Count = 0 Then Exit For
ActiveWorkbook.Connections.Item(i).Delete
i = i - 1
Next i
Application.DisplayAlerts = True
End Sub
Run Code Online (Sandbox Code Playgroud)
PS收到错误
ActiveWorkbook.Connections.Item(i).Delete
Run Code Online (Sandbox Code Playgroud)