PDA

View Full Version : [SOLVED:] Refresh specific power queries within workbook



JILBO
04-29-2021, 08:11 AM
Hi,

Wondering if anyone has figured out how delete specific queries in a workbook?

The below deletes all, but I want to remove a specific one as well before


Public Sub RemoveQueries()

'Removes all PowerQueries from Workbook
Dim cn As WorkbookConnection
Dim qr As WorkbookQuery
On Error Resume Next
For Each cn In ThisWorkbook.Connections
cn.Delete
Next
For Each qr In ThisWorkbook.Queries
qr.Delete
Next
End Sub

PS: See Post $4. st

SamT
04-29-2021, 09:36 PM
Sub WhichQueiries()
Dim qr As WorkbookQuery
Dim Rw as Long
Rw = 1

Sheets.Add Name = "Query Names"

With Sheets("Query Names")
For Each qr In ThisWorkbook.Queries
Rw = Rw + 1
.Cells(Rw, 1) = qr.Name
.Cells(Rw, 2) = qr.Parent
.Cells(Rw, 3) = qr.Formula
.Cells(Rw, 4) = qr.Description
Next
End With
End Sub

You should be able to delete Queries by Name: ThisWorkbook.Queries("Name").Delete

You should also be able to use any property with an If...Then:

If qr.Formula = "let Source = Blah, Blah, Blah" Then
qr.Delete
End If

JILBO
05-01-2021, 01:01 PM
Thanks for the reply, I’m going to give that a go and see how inget
on !!

JILBO
05-04-2021, 03:12 AM
Ok that works a treat, on another related question how do you run just specific workbook Power Queries as well (Instead of just all of them at once) ???

SamT
05-04-2021, 05:21 AM
I don't do queries, but I thimk you refresh that Query's connection