Question: I am trying to write a sub to delete all queries in a workbook. I have got the code below:

```
Dim CN As Variant
Dim qTable As QueryTable

For Each CN In ThisWorkbook.Connections
    CN.Delete
Next CN

 For Each qTable In Sheets("Property Extract 1").QueryTables
qTable.Delete
Next qTable'

```

The connection deletion works fine but the queries remain. Any ideas how to delete all queries in a workbook?

I was planning to replicate the query deletion for 2 or 3 sheets.

thanks

Answer: 
Clear all connection in activeworkbook without any error. you must convert the Object to as String in order delete all connections

```
Sub ClearQueries()
    Dim pq As Object
    Dim q As String
    For Each pq In ThisWorkbook.Queries
        q = pq
        ActiveWorkbook.Queries(q).Delete
    Next
End Sub

```
I Excel 2016 I was able to select all by maintaining CTRL and clicking on each in the Workbook queries pane. Then right-click --> Delete.