I have created a macro that removes all the data connections from a workbook. When I run it all the connections are removed but then I get this error:
Run-time error '5':
Invalid procedure call or argument
The code is:
Sub RemoveConnections()
For i = 1 To ActiveWorkbook.Connections.Count
If ActiveWorkbook.Connections.Count = 0 Then Exit Sub
ActiveWorkbook.Connections.Item(i).Delete
i = i - 1
Next i
End Sub
Can somebody help me out? Not sure why it's erroring out instead of just ending once all the connections are removed.