VBA & Macro Problems

How to Run an Excel Hyperlink Macro After Power Query Refresh

Adam DavisAdam Davis Oct 28, 2026 868 views

Question details

The user needs to execute a VBA macro that adds hyperlinks immediately after a Power Query refresh is completed.

How to Run a Hyperlink Macro Automatically After a Power Query Refresh
Product
Excel
Device & OS
not provided
Scenario
Updating a data table via Power Query, which overwrites the existing worksheet cells and removes VBA-generated hyperlinks in the process.
Observed behavior
When Power Query refreshes, it deletes the hyperlinks created by previous VBA macros. The user must find a way to trigger the macro automatically once the data refresh finishes.
Before you start

Before attempting to automate the macro execution, ensure that you have disabled 'Background Refresh' in your Power Query properties so VBA does not trigger the hyperlink macro before the data finishes loading.

Solution 1Recommended

Use a Master VBA Macro with Background Refresh Disabled

The most reliable method is to disable background refresh for your query and use a single master macro to first refresh the data and then run the hyperlink macro sequentially.

Power Query operates asynchronously by default, meaning VBA will continue executing the next lines of code while the query is still refreshing data. By disabling the background refresh, you force Excel to wait until the query finishes loading before moving to the hyperlink macro code.

1
Disable Background Refresh

Navigate to the 'Data' tab and click 'Queries & Connections'. Right-click your query, select 'Properties', and uncheck 'Enable background refresh' under the Usage tab. Click OK.

2
Open the VBA Editor

Press 'Alt + F11' on your keyboard to open the Visual Basic for Applications (VBA) editor.

3
Create the Master Macro

Insert a new module and write a macro that refreshes the workbook using 'ActiveWorkbook.RefreshAll'. On the next line, type the name of your hyperlink macro (e.g., 'Call AddHyperlinks').

4
Run the Master Macro

Instead of refreshing the query from the Excel ribbon, run this new master macro whenever you need to update your data and apply the hyperlinks.

Use a Master VBA Macro with Background Refresh Disabled
Data Integrity Maintained: Disabling background refresh ensures your hyperlink macro will always target the newly loaded Power Query data without timing errors.
Free Microsoft Office alternative

Need a simpler way to manage spreadsheet data? Try WPS Office

If you frequently struggle with complex VBA workarounds and Power Query refresh issues in Microsoft Excel, consider WPS Office. It provides a highly compatible, free, and lightweight alternative for all your spreadsheet needs without the steep learning curve.

  1. 1. Download the software: Visit the official WPS Office website to download the free installation package for your operating system.
  2. 2. Open your macro-enabled files: Launch WPS Spreadsheet and seamlessly open your existing .xlsm files without losing data.
  3. 3. Enable VBA features: If your workbook relies on macros, ensure you activate the built-in VBA environment within WPS to execute your automated tasks.
Free and lightweight office suite for daily tasksHigh compatibility with Microsoft Excel formats (.xlsx, .xlsm, .csv)Built-in support for VBA macros and advanced formulasClean, user-friendly interface for effortless data management
microsoft office alternative - wps office

Frequently Asked Questions

Why do my custom hyperlinks disappear after a Power Query refresh?

Power Query essentially drops and recreates the data table upon refreshing. Any custom cell formatting, including manual or VBA-generated hyperlinks applied directly to the worksheet, gets overwritten by the incoming raw data.

How do I turn off background refresh for Power Query?

Go to the 'Data' tab on the ribbon, select 'Queries & Connections', right-click the specific query, choose 'Properties', and uncheck the 'Enable background refresh' option under the Usage tab.

Can I use an AfterRefresh event for Power Query instead of a master macro?

Yes, but it requires setting up an application-level event handler or a Class Module using the QueryTable.AfterRefresh event, which is significantly more complex than turning off background refresh and running a sequential macro.