Delete a query from excel workbook with Vba
Try adding the following line.
The Activeworkbook.Queries() takes a Name or Index
ActiveWorkbook.Queries("Query1").Delete
Delete all queries in a workbook
First off, you cannot delete PQ Queries from VBA unless you are on Excel 2016/365. PQ is not exposed to VBA in earlier versions even when the add-on is installed. If you have the right version of Excel, you can delete the PQ Queries themselves just like you are clearing the connections:
Dim pq As Object
For Each pq In ThisWorkbook.Queries
pq.Delete
Next
Delete unwanted queries in VBA
You could use Application.Match
with the query name.
If IsError(Application.Match(qr.Name, queries, 0)) Then ' query name is not in list
Related Topics
Oracle Db: How to Write Query Ignoring Case
What's the Difference Between "Like" and "=" in SQL
Varchar2(N Byte|Char) Default -> Char or Byte
Lost the Intellisense in SQL Server Management Studio
Is There Any Better Option to Apply Pagination Without Applying Offset in SQL Server
SQL Get "Iso Year" for Iso Week
How to Select Top 3 Values from Each Group in a Table with SQL Which Have Duplicates
Remove Reverse Duplicates from an SQL Query
Transpose Column Headers to Rows in Postgresql
Convert Number to Words - First, Second, Third and So On
SQL Server Case .. When .. in Statement
Meaning of "Select Tables Optimized Away" in MySQL Explain Plan
Bulk Insert with Variable File Name
How to Grant All Privileges on Views to Arbitrary User