Some time back I posted a routine to refresh Power Queries with VBA, allowing you to refresh all Power Queries in a workbook.
The challenge with that specific macro is that it refers to the connection name, which may not always start with Power Query. (As we move closer to Excel 2016, we are now aware that these queries will NOT have names starting with Power Query.)
I have seen an approach where someone modified the code I provided earlier to include a variable, allowing you to easily change the prefixed text from Power Query to something else. While that works, it’s still not ideal, as names can be volatile. It makes more sense to try and find a method that is cannot be broken by a simple name change.
Refresh Power Queries With VBA
The macro below is a more targeted approach that checks the source of the query. If it is a connection that is built against Power Query engine (Microsoft.Mashup), then it will refresh the connection, otherwise it will ignore it.
Public Sub UpdatePowerQueriesOnly()
Dim lTest As Long, cn As WorkbookConnection
On Error Resume Next
For Each cn In ThisWorkbook.Connections
lTest = InStr(1, cn.OLEDBConnection.Connection, "Provider=Microsoft.Mashup.OleDb.1")
If Err.Number <> 0 Then
If lTest > 0 Then cn.Refresh
This macro works with Excel 2010, 2013 and 2016, and should survive longer than the original version I posted.