Quantcast
Channel: Excel IT Pro Discussions forum
Viewing all articles
Browse latest Browse all 11829

VBA to remove all data connections (Excel 2013)

$
0
0

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.




Viewing all articles
Browse latest Browse all 11829

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>