Automate Excel Power Query Refresh: Step-by-Step
In this article
Yes, you can automate Power Query refreshes in Excel so your queries update on their schedule instead of you clicking Refresh All every time. The quickest method is built right in: tell Excel to refresh all queries when the file opens, and optionally refresh in the background at a set interval. For hands-free updates you can combine that with a scheduled task in Windows or a simple VBA macro. Below is everything you need to set it up.
What You'll Need
- Excel for Windows or Mac (this guide focuses on Windows; a couple of steps differ on Mac and are noted)
- A workbook with at least one Power Query already loaded to a worksheet or the data model (Data > Get Data)
- The source files, folders or databases your queries pull from must be reachable whenever the refresh runs
- For full automation without opening the file: the desktop version of Excel (the browser version in Microsoft 365 does not support scheduled refreshes) and, for the Task Scheduler method, a Windows PC that stays on at the refresh time
Step-by-Step
Menu labels can differ slightly between Excel versions and regions; the paths below are from current Windows versions of Excel.
Method 1: Refresh when the file opens
- Open your workbook in Excel.
- Go to Data > Queries & Connections to see the Queries & Connections pane on the right.
- Right-click each query in the pane and choose Properties.
- In the Properties dialog, tick the box for Refresh data when opening the file.
- Repeat for every query you want to auto-refresh, then save the workbook.
Method 2: Refresh at a timed interval while the file is open
- In the same Properties dialog from Method 1, tick Refresh every and enter the number of minutes between refreshes.
- Tick Enable background refresh if you want to keep working while the update runs. Leave it unticked only if later queries depend on the refresh finishing first.
- Click OK and save. Excel will now refresh that query automatically at the interval you set, as long as the file is open.
Method 3: Refresh all queries on open with one setting
- Go to Data > Queries & Connections, and instead of setting each query individually, click a query, then use Shift+click to select all of them.
- Right-click the selection, choose Properties, and set the open-refresh and interval options once for all selected queries.
- Alternatively, apply the setting to all future queries: File > Options > Data, and under Default Query Refresh Settings choose how new queries behave. Existing queries keep their own settings, so Methods 1 and 2 still apply to those.
Method 4: Fully hands-free with VBA and Task Scheduler (Windows)
- Save your workbook as a macro-enabled workbook (.xlsm).
- Press Alt+F11 to open the VBA editor, then double-click ThisWorkbook in the Project pane.
- Paste this code:
Private Sub Workbook_Open()
ThisWorkbook.RefreshAll
Application.OnTime Now + TimeValue("00:00:30"), "SaveAndClose"
End Sub
Sub SaveAndClose()
ThisWorkbook.Save
Application.Quit
End Sub - Save, then open Windows Task Scheduler (search for it in the Start menu).
- Create a Basic Task, set the trigger to your schedule (daily at a set time, for example), and set the action to start Excel and open your file: in the Program/script box put the full path to EXCEL.EXE, and in Add arguments put the full path to your workbook in quotes.
- Test by right-clicking the task and choosing Run. The workbook should open, refresh, save and close. The 30-second delay in the macro gives slower queries time to finish; increase it if your data takes longer.
Note: the Workbook_Open macro only runs if macros are enabled. If Excel blocks macros in files from the internet or certain folders, move the file to a trusted location or enable macros in File > Options > Trust Center when prompted.
Method 5: Refresh on a schedule in the cloud
If your queries live in a workbook stored in OneDrive or SharePoint and you use Power BI, you can schedule refreshes of semantic models from the Power BI service instead. Plain Excel files in OneDrive do not refresh Power Query on a timer by themselves, so Methods 1 to 4 remain the options for a local workbook.
Common Mistakes
- Setting the refresh interval but leaving the file closed. Timed refreshes only run while the workbook is open; use Task Scheduler for true hands-free updating.
- Forgetting that Merged queries and appended queries depend on their source queries. Refresh the dependencies first, or untick background refresh so steps run in order.
- Saving as .xlsx after adding VBA, which silently strips the macro. Always save as .xlsm.
- Pointing queries at files on a network drive or SharePoint folder that prompts for credentials. A scheduled refresh that hits a password prompt will hang or fail.
- Editing loaded query output directly in the worksheet. Manual changes are wiped on every refresh, since the load overwrites the range.
- Using Excel for the web and expecting these settings to work. Query properties and VBA are desktop features.
Tips
- Combine Method 1 with Method 2: refresh on open plus a background interval covers most daily workflows with zero code.
- Use Data > Refresh All (or Ctrl+Alt+F5 for a full refresh that also clears the query cache) to test manually after changing settings.
- Keep source data on stable paths. If you move a folder, every query pointing to it breaks; fix this in Data > Get Data > Data Source Settings.
- On Mac, query Properties are available through the Queries & Connections pane but the dialog has fewer options than Windows, and VBA support for Power Query is limited, so Windows is the better choice for automation.
- For large workbooks, disable background refresh on the final query in a chain so dependent tables never show mixed old and new data.
Troubleshooting
- Refresh works manually but not on open: check the query Properties again; the setting is per query, and newly added queries will not have it.
- Scheduled task opens Excel but nothing happens: check whether macros are disabled (look for a security warning above the formula bar) and confirm the file is saved as .xlsm.
- Query fails with a data source error during automated refresh: run it manually to see the exact message; most often the source file is locked by another user or the path has changed.
- Refresh takes too long and the file closes before finishing: increase the delay in the OnTime line of the macro, or refresh only the queries you need.
- Refreshed data appears but does not save: make sure the SaveAndClose macro is present and spelled exactly the same in the OnTime call.
- Queries grayed out or settings missing: you may be in Excel for the web, or the workbook is in compatibility mode; re-save it as a current .xlsx or .xlsm file.
Frequently Asked Questions
Can Excel refresh Power Query automatically without opening the file?
Not on its own. Desktop Excel only refreshes while the file is open, so fully unattended refreshes need Task Scheduler (Method 4) or a cloud service like Power BI if the data is stored there.
Does this work in Excel for the web?
Partially. Excel for the web can refresh some queries manually, but the Properties dialog, timed refresh and VBA are desktop-only features.
Why does my table revert my manual edits?
Because the loaded query output is overwritten on every refresh. Put any manual calculations in columns outside the loaded table, ideally in a separate sheet referencing the query results.
Is VBA safe to use for this?
Yes, when the macro is one you created and the file is stored in a trusted location. Keep macro-enabled files out of shared untrusted folders and never enable macros in files from unknown sources.
Can I refresh queries from a SharePoint or web source?
Yes, if credentials are saved. Set the authentication once via Data > Get Data > Data Source Settings, then automated refreshes will use the saved credentials.