Delete all external data connections at once

maounde

New Member
Joined
Jan 8, 2008
Messages
22
I have a file with hundreds of external data connections (to local CVS files imported). I need to remove these CVS files from my system. I'd rather break the connections from my XLSX file to these. On Excel 2016, I know I can break each connection one by one (Data > Queries & Connections > delete , confirm yes.... each time).

Is there a way to break these connections all at once, instead of one by one?
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi there,
I have a macro that does it for my use, maybe the code will can help you too
Code:
Public Sub RemoveQueries(ByVal WKS As Worksheet)
Dim QRT                     As QueryTable
If WKS.QueryTables.Count > 0 Then
    For Each QRT In WKS.QueryTables
        QRT.Delete
    Next QRT
End If
End Sub
 
Upvote 0
@Keebellah I am trying to adapt your macro to my situation. I am not experienced in this at all and need more help.

I created a dummy macro and edited it a bit. I tried to run it on a test file and got this:

1662560100916.png

When I tried to debug, it shows this:
1662560152581.png

Any suggestion?
 
Upvote 0
So the code should be like this below?

Public Sub RemoveQueries(ByVal WKS As Worksheet)
Dim WKS As WorkSheet
If WKS.QueryTables.Count > 0 Then
QRT.Delete
Next QRT
End If
End Sub
 
Upvote 0
You dim ALL variable, and probably due to my error you changed it
Here's how it should be
Code:
Public Sub RemoveQueries(ByVal WKS As Worksheet)
Dim WKS                     AS WorkSheet
Dim QRT                     As QueryTable
If WKS.QueryTables.Count > 0 Then
    For Each QRT In WKS.QueryTables
        QRT.Delete
    Next QRT
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,462
Members
449,085
Latest member
ExcelError

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top