logo
search
Power Query Problems

How to Refresh Power Query When a Named URL Changes in Excel

Adam DavisAdam Davis Oct 10, 2026 868 views

Question details

The user needs a way to automatically refresh a Power Query connection whenever a URL stored dynamically in a named Excel cell changes.

How to Refresh Power Query When a Named URL Changes in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
Reading data from a dynamic web URL stored in an Excel cell and ensuring the query pulls the new data immediately when the URL is modified.
Observed behavior
Power Query can read the URL from a named cell using Excel.CurrentWorkbook, but it cannot automatically detect cell changes to trigger a refresh on its own without external mechanisms.
Before you start

Ensure that your workbook is saved as a Macro-Enabled Workbook (.xlsm) and that macros are enabled in your Trust Center settings, as automating the refresh process requires VBA.

Solution 1Recommended

Automate Query Refresh Using a VBA Worksheet Event

Use a VBA macro triggered by a worksheet change event to automatically refresh the query whenever the named URL cell is modified.

Since Power Query cannot continuously monitor a cell for changes natively, a VBA Worksheet_Change event is the most efficient way to automate the refresh. This script will listen for changes in your specific URL cell and command Excel to refresh the data connection immediately.

1
Name the URL Cell

Select the cell containing your web URL, click the Name Box (next to the formula bar), type 'SourceURL' (without quotes), and press Enter.

2
Open the VBA Editor

Press ALT + F11 on your keyboard to open the Visual Basic for Applications editor.

3
Insert the Worksheet Event Code

In the Project Explorer on the left, double-click the sheet name where your 'SourceURL' cell is located. Paste a Worksheet_Change subroutine that targets your named range.

4
Add the Refresh Command

Inside the VBA subroutine, add the command 'ActiveWorkbook.Connections("Query - YourQueryName").Refresh' to trigger the update when the target cell changes.

5
Save as Macro-Enabled

Close the VBA editor and save your Excel file as an Excel Macro-Enabled Workbook (*.xlsm) to ensure the script runs in the future.

Automate Query Refresh Using a VBA Worksheet Event
Correct Query Name: Ensure you replace 'YourQueryName' in the VBA code with the exact name of your Power Query connection, which can be found in the Queries & Connections pane.
Free Microsoft Office alternative

Experience Seamless Data Management with WPS Office

If you are managing complex datasets and macros but want a faster, more lightweight solution, WPS Office Spreadsheets is an excellent free alternative. It offers powerful data processing tools, seamless VBA support, and high compatibility with Excel files.

Fully compatible with Microsoft Excel formats (.xlsx, .xlsm, .csv) ensuring your macros and formulas work perfectly.Built-in VBA and macro support for automating repetitive data fetching tasks.Lightweight, fast installation with a familiar interface that requires zero learning curve.Free to download and use for your everyday spreadsheet and data analysis needs.
microsoft office alternative - wps office

Frequently Asked Questions

Can Power Query automatically detect changes in an Excel cell without VBA?

No, Power Query does not have built-in triggers to auto-refresh based on cell modifications. You must manually click 'Refresh All' on the Data tab, or use a VBA worksheet event macro to detect the change and trigger the refresh programmatically.

How do I read a named cell value in Power Query?

You can retrieve a named cell's value by using the M code formula 'Excel.CurrentWorkbook(){[Name="YourNamedRange"]}[Content]{0}[Column1]' in the Power Query Advanced Editor.

Why isn't my VBA macro triggering the query refresh?

Ensure that macros are enabled in your Trust Center settings and the file is saved as an .xlsm. Additionally, verify that your Worksheet_Change event targets the exact cell address or named range where the URL is stored, and that the connection string name perfectly matches your query.

Can I use Power Automate to refresh the query instead of VBA?

Yes, Power Automate (formerly Microsoft Flow) can be used to run a script or refresh a dataset online, but it generally requires the file to be hosted on SharePoint or OneDrive and often utilizes Office Scripts instead of traditional VBA.