Consulting

Results 1 to 5 of 5

Thread: Refresh specific power queries within workbook

  1. #1
    VBAX Regular
    Joined
    Dec 2020
    Posts
    48
    Location

    Refresh specific power queries within workbook

    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
    Last edited by SamT; 05-04-2021 at 05:29 AM.

  2. #2
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,709
    Location
    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
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Regular
    Joined
    Dec 2020
    Posts
    48
    Location
    Thanks for the reply, I’m going to give that a go and see how inget
    on !!

  4. #4
    VBAX Regular
    Joined
    Dec 2020
    Posts
    48
    Location
    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) ???

  5. #5
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,709
    Location
    I don't do queries, but I thimk you refresh that Query's connection
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •