I know that since Excel 2016 I can simply delete a query like this:
ActiveWorkbook.Queries("aaa").delete
However this will leave an "orphaned" query connection. So if I refresh the remaining structured table, I will see the error
Query xxx was not found
I know that I can avoid this by first unlinking the query like this:
ActiveSheet.ListObjects("aaa").Unlink
How can I combine these 2 codes into a macro that:
- Takes the query name as input (name in the Power Query Editor list)
- Remove the link to the structured table
- Delete that query
I prefer a method that works in the Queries collection of ActiveWorkbook. Because ListObjects is Sheet-dependent, and sheet name may change. Something like this:
ActiveWorkbook.Queries("aaa").[something].unlink
ActiveWorkbook.Queries("aaa").delete