title: Killing connection in EXCEL vba
body: <p>I am trying to removeconnection from my work book but I am still geting run-time error 5. I dont know what to do because in my other projects it works.</p>
  
  <p>Thanks for advice. Greeting from czech Republic.  </p>
  
  <pre><code>    Sub refresh_all()
  
      Dim i As Integer
      '~~&gt; refresh workbook query
      Application.DisplayAlerts = False
  
      Workbooks("UAC_report_p.xlsb").Activate
  
      '~~&gt; wait for refresh then execute Call save_as
      Do Until Application.CalculationState = xlDone
      DoEvents
      Loop
  
      ActiveWorkbook.RefreshAll
  
      Workbooks("UAC_report_p.xlsb").Activate
  
      '~~&gt;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
  </code></pre>
  
  <p>P.S. getting error on </p>
  
  <pre><code>ActiveWorkbook.Connections.Item(i).Delete
  </code></pre>