Delete all power query connections & source info VBA

JoeVBAHelp

New Member
Joined
Aug 25, 2016
Messages
14
Hi all

I am trying to write some VBA code to delete all Power query connections & Sources from my workbook.

So far I have the code below, this does delete the connections but when I open the 'Show Queries' list all of my queries are still there.

FYI I dont want to delete the actual tables, just the links to the power query so I can send to somebody else and they just get the data.

Workbook has 23 separate queries and need to send every week, would save me a lot of time with some VBA code

Thanks for you help!


Code:
Sub DeleteAllPQ()

Dim cn As Object
Dim ws As Worksheet
Dim qryT As QueryTable


For Each cn In ActiveWorkbook.Connections
    cn.Delete
Next cn
For Each ws In ActiveWorkbook.Worksheets
    For Each qryT In ws.QueryTables
         qryT.Delete
    Next qryT
Next ws
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,216,291
Messages
6,129,911
Members
449,540
Latest member
real_will_smith

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