Fix Excel VBA Error 1004 When Refreshing Power Query Connections
Question details
Resolve a VBA error when refreshing Power Query queries in Excel.

- Product
- Microsoft Excel Power Query and VBA
- Device & OS
- not provided
- Scenario
- A macro refreshes Power Query queries in a workbook, possibly after a Microsoft 365 update.
- Observed behavior
- Excel displays VBA error 1004 stating that a connection has no query associated with it.
Open the affected workbook and check Data > Queries & Connections for the query and connection names. Identify which connection triggers the error and whether it is used by a table, PivotTable, or the Data Model before removing it.
Remove obsolete connections and update the refresh macro
Use this approach when the macro references a connection that is no longer associated with a Power Query query.
In Excel, select Data > Queries & Connections. Review the Queries and Connections tabs and note the names used by the affected query and macro.
On the Connections tab, select the suspect connection and inspect its properties and related workbook objects. Confirm that it is not needed by a query, table, PivotTable, or Data Model.
Right-click a connection that you have confirmed is unused and select Delete. Leave connections in place if you cannot verify whether they are needed.
Open the VBA editor with Alt+F11, find the refresh procedure, and replace stale connection names with the names of existing queries or their loaded tables. For example, a query can be refreshed with ThisWorkbook.Queries("QueryName").Refresh after replacing QueryName with its actual name.
Run the updated macro from the VBA editor or its workbook button. Check that the intended query refreshes without error and that its output is current.

Recreate the affected Power Query connection
Use this if the connection remains broken after you verify the macro and remove confirmed obsolete entries.
Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Microsoft Office format compatibility for easier migration. It does not repair Excel Power Query connections or guarantee compatibility with Excel VBA macros.

Frequently Asked Questions
Why does Excel say a connection has no query associated with it?
The macro may be referring to an obsolete connection or using a connection as though it were linked to a Power Query query. Check Data > Queries & Connections and compare the entries with the names in the VBA procedure.
Can I delete every connection that has no matching query?
No. Some connections support PivotTables, the Data Model, or other workbook features. In Data > Queries & Connections, inspect the connection and confirm it is unused before deleting it.
How do I refresh one Power Query query from VBA?
In the VBA editor, use ThisWorkbook.Queries("QueryName").Refresh, replacing QueryName with the existing name shown under Data > Queries & Connections. Test the macro to confirm the expected output refreshes.
What should I do if the error appeared after a Microsoft 365 update?
First inspect the query and connection names and test the macro again. If the affected connection remains broken, recreate the query or its load and update the macro to reference the current query or table.




