How to Refresh Power Query When a Named URL Changes in Excel
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.

- 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.
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.
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.
Select the cell containing your web URL, click the Name Box (next to the formula bar), type 'SourceURL' (without quotes), and press Enter.
Press ALT + F11 on your keyboard to open the Visual Basic for Applications editor.
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.
Inside the VBA subroutine, add the command 'ActiveWorkbook.Connections("Query - YourQueryName").Refresh' to trigger the update when the target cell changes.
Close the VBA editor and save your Excel file as an Excel Macro-Enabled Workbook (*.xlsm) to ensure the script runs in the future.

Configure Dynamic URL in Power Query and Refresh Manually
Set up Power Query to dynamically read the named cell's URL so you can simply use the built-in 'Refresh All' button when the URL changes.
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.

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.




