vba code to refresh a connection only query

drop05

Active Member
Joined
Mar 23, 2021
Messages
285
Office Version
  1. 365
Platform
  1. Windows
Hi am am trying to see if there is vba code to refresh a query that is a "Connection Only"

i have the below code i am using but i am not seeing the query refresh when i go step by step in the code

VBA Code:
Sub RefreshSpecificQueries()

    Dim queryList As Variant
    Dim i As Integer
    Dim conn As WorkbookConnection

    ' Add your query names to this array
    queryList = Array("Query - filepath_Data", "Query - filepath_Dataset")

    On Error Resume Next
    For Each conn In ThisWorkbook.Connections
        For i = LBound(queryList) To UBound(queryList)
            If conn.Name = queryList(i) Then
                conn.OLEDBConnection.BackgroundQuery = False
                conn.Refresh
            End If
        Next i
    Next conn

End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Why would you need to refresh it? It will refresh when it's used.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top