VBA & Macro Problems

Fix Excel VBA Error 1004 When Refreshing Power Query Connections

Steven ParkerSteven Parker Nov 18, 2026 869 views

Question details

Resolve a VBA error when refreshing Power Query queries in Excel.

Fix Excel VBA Error 1004 When Refreshing Power Query Connections
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.
Before you start

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.

Solution 1Recommended

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.

1
Inspect queries and connections

In Excel, select Data > Queries & Connections. Review the Queries and Connections tabs and note the names used by the affected query and macro.

2
Check connection usage

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.

3
Remove obsolete connections

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.

4
Update the macro

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.

5
Test the refresh

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.

Remove obsolete connections and update the refresh macro
Check connection dependencies: Not every connection is a Power Query connection. A connection without a matching query may still be needed elsewhere in the workbook.
Free Microsoft Office alternative

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.

Open and edit Microsoft Excel XLSX and XLS filesUse a familiar spreadsheet interface for everyday workbook tasksWork with workbook data without relying on the affected Excel refresh macroMove common Office documents into a lightweight, free suite
QA img-9

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.