Forum Discussion
Office 365 - Delete data connections in one go
- Feb 04, 2018
you can use this vbscript in a Macro button:
Sub Remove() Dim connection As WorkbookConnection Dim query As WorkbookQuery On Error Resume Next For Each connection In ThisWorkbook.Connections connection.Delete Next For Each query In ThisWorkbook.Queries query.Delete Next End Sub
you can use this vbscript in a Macro button:
Sub Remove() Dim connection As WorkbookConnection Dim query As WorkbookQuery On Error Resume Next For Each connection In ThisWorkbook.Connections connection.Delete Next For Each query In ThisWorkbook.Queries query.Delete Next End Sub
Hi, Pablo R. Ortiz
I have a spread sheet which has created about 60,000 data connections which is obviously going very slow. I have used your script which solves the speed problem but i i need to retain about 100 good connections. Is there a way i can exclude refreshed connections?
Thanks
- pnavarroApr 23, 2020Copper Contributor
Hi JasonBoull. This is my first time answering here (and I am quite late but found the same problem). I am no expert, but I would take what Pablo R. Ortiz posted before and add exceptions:
Sub Remove() Dim connection As WorkbookConnection Dim query As WorkbookQuery On Error Resume Next For Each connection In ThisWorkbook.Connections If connection.PARAMETER<>"Condition" Then Next Else connection.Delete Next For Each query In ThisWorkbook.Queries query.Delete Next End Sub
See that I added a condition to the script, where you compare your connections parameters to some condition. If there are several conditions maybe you could nest an array and compare them all.
Hope it helps.
Pedro