How to Refresh Excel Data With Power Automate
Power Automate can refresh Excel data through desktop Excel, but a cloud flow cannot generally refresh a workbook’s Power Query connections with an Office Script. The right approach depends on whether you need to reload external data, update worksheet values, recalculate formulas, or refresh a Power BI model. This guide explains the difference, provides a desktop refresh workflow, and shows where cloud automation fits.
What Excel Refresh Means in Power Automate
“Refresh Excel” can mean several different operations:
- Refresh external data: Run a query or connection again and load its results into the workbook.
- Update worksheet data: Write new values into cells or table rows.
- Recalculate formulas: Calculate results using data already available to the workbook.
- Refresh a Power BI semantic model: Update data held in Power BI, not the original Excel file.
These operations are not interchangeable. Adding rows through the Excel Online connector does not execute Power Query, and recalculating formulas does not fetch new records from an external source.
The important cloud limitation concerns Office Scripts. When an Office Script runs through Power Automate, workbook.refreshAllDataConnections() refreshes Power BI-backed connections; it does not provide a general refresh for other external connections. For unsupported sources, the method can return successfully without refreshing anything.
A successful automation run proves that the actions completed, not that the workbook contains fresh source data.
For ordinary Power Query connections, start with desktop Excel if the refreshed results must be saved back into the workbook. If only a dashboard needs current data, refreshing its Power BI model may be the better design.
How to Refresh Excel Data With Power Automate Desktop
Choose the execution route before building the flow.
| What Needs to Change | Appropriate Route | Important Boundary |
|---|---|---|
| Power Query results or external connections saved in Excel | Power Automate Desktop controlling desktop Excel | Requires Excel and an available Windows machine |
| Cells or Excel table rows | Excel Online (Business) actions or an Office Script | Writing data does not execute existing queries |
| Formula results using existing workbook data | Office Script calculation | Recalculation is not an external-data refresh |
| A Power BI semantic model built from Excel data | Power BI refresh | Does not refresh and save the original workbook |
The desktop workflow below uses a VBA macro to invoke Excel’s refresh operation, then validates a source-backed value before saving.
Step 1: Make the Workbook Refresh Successfully by Hand
- Open a working copy of the workbook in desktop Excel.
- Select Data > Refresh All.
- Resolve any credential prompts, privacy-level errors, missing files, or connection failures.
- Open Data > Queries & Connections and confirm that the expected queries have finished successfully.
- Identify a value in the loaded results that you can compare against the source, such as a record identifier, revised amount, or source-generated update timestamp.
For the initial test, use an approved test record whose value you can safely change. Note the expected replacement value before running the automation. This gives you evidence of a real refresh rather than merely evidence that Excel opened.
For connections that expose the Enable background refresh setting in their properties, clear it for this synchronous workflow. Background refresh can let automation continue while data is still loading.
Do not automate an unresolved manual refresh failure. The desktop flow will otherwise encounter the same error, often as a prompt nobody is available to answer.
Step 2: Add a Refresh Macro
- Save the working copy as an Excel Macro-Enabled Workbook with the
.xlsmextension. - Open Developer > Visual Basic.
- In the workbook’s VBA project, select Insert > Module.
- Paste this macro into the module:
Public Sub RefreshWorkbookData()
ThisWorkbook.RefreshAll
Application.CalculateUntilAsyncQueriesDone
Application.CalculateFull
End Sub
- Save the workbook.
- Run the macro manually and confirm that the changed source value appears in the loaded data.
ThisWorkbook deliberately targets the workbook containing the macro rather than whichever workbook happens to be active.
The waiting method also has a boundary: CalculateUntilAsyncQueriesDone handles pending OLE DB and OLAP queries. It is not a universal completion check for every Excel connector or add-in. Keep the source-value validation in the flow, even when this macro appears to wait correctly.
Use your organization’s approved macro-trust process. Do not globally enable all macros just to make the flow run.
Step 3: Create the Desktop Flow
- Open Power Automate Desktop and create a desktop flow.
- Add Launch Excel and configure it to open the macro-enabled workbook.
- Keep Excel visible during development so you can detect authentication dialogs or other interruptions.
- Add Run Excel macro, using the Excel instance created by the launch action.
- Set the macro name to
RefreshWorkbookData.
Use a stable local file location. A locally synchronized OneDrive or SharePoint file can work, but the desktop flow must open its local path, not a browser sharing URL.
Close other editing sessions for the workbook before testing. Avoid having a cloud flow and desktop flow write to the same file simultaneously.
Step 4: Validate the Loaded Data Before Saving
- Add Read from Excel worksheet after the macro action.
- Read the cell containing the source-backed test value.
- Use an If condition to compare it with the expected value.
- Continue to the save actions only when the values match.
- If the check fails, record the mismatch and end the run as unsuccessful without treating the workbook as refreshed.
For a production flow, replace the temporary test value with a durable freshness check. Useful checks include a source version identifier, an upstream batch identifier, or a source-generated update timestamp.
A timestamp written by the automation itself is not a freshness check: it can change even if every query remains stale. A row count alone is also insufficient when existing rows can change without changing the count.
Do not substitute an arbitrary delay for validation. If a connection cannot run synchronously, use its actual completion signal together with a source-backed check before allowing the workbook to be saved.
Step 5: Save, Close, and Test the Trigger
- On the successful validation branch, add Save Excel.
- Add Close Excel to release the workbook.
- Run the desktop flow manually.
- Reopen the saved file and confirm that the expected source value persisted.
- Only then connect the desktop flow to its intended trigger.
Configure the machine connection and the licensing required for the intended attended or unattended mode; creating a desktop flow alone does not provide unattended execution.
If the workbook is synchronized to cloud storage, confirm that synchronization finishes before a later cloud action consumes the file.
Cloud Workbook Updates With Office Scripts
Office Scripts are useful when the task is to write values, transform data already in the workbook, or recalculate formulas. They are not a general workaround for refreshing unsupported external connections.
The following example verifies that a cloud flow can access the intended worksheet and recalculate the workbook.
Prepare an Explicitly Named Worksheet
- Save a test workbook in OneDrive for Business or a SharePoint document library.
- Create a worksheet named
RefreshStatus. - Open the workbook in Excel for the web.
- Select Automate > New Script > Create in Code Editor.
Use stable workbook and worksheet names, and avoid relative references such as Workbook.getActiveWorksheet, following Microsoft’s Office Scripts guidance. A cloud flow should not depend on whichever worksheet was active during a previous editing session.
If the Automate tab is unavailable, verify Office Scripts access, licensing, and your organization’s settings before building the flow.
Create the Calculation and Diagnostic Script
Replace the default code with:
function main(workbook: ExcelScript.Workbook) {
const worksheet = workbook.getWorksheet("RefreshStatus");
if (!worksheet) {
throw new Error("The RefreshStatus worksheet was not found.");
}
workbook.getApplication().calculate(ExcelScript.CalculationType.full);
const timestamp = new Date().toISOString();
worksheet.getRange("A1").setValue(timestamp.slice(0, 10));
worksheet.getRange("B1").setValue(timestamp.slice(11, 19));
}
The script writes the current date to A1 and the current time to B1. It also explicitly checks for the worksheet so that a renamed or missing sheet produces an error rather than an unintended write.
Save the script with a recognizable name, such as RecalculateAndStamp.
Connect and Test the Cloud Flow
- Create an instant cloud flow with Manually trigger a flow.
- Add the Excel Online (Business) connector’s Run script action.
- Select the workbook’s location, document library, and file.
- Select the saved script.
- Save the flow.
- From the Power Automate home page, open My flows, select the flow, and choose Run flow.
- Inspect the run history, then reopen or refresh the workbook to verify the output.
The standard Run script action runs a script stored in your OneDrive against the selected workbook. If the script itself is stored in a team SharePoint library, use Run script from SharePoint library instead. The location of the script and the location of the workbook are separate choices.
Power Automate uses Coordinated Universal Time (UTC), so the time written by this script may differ from your local clock. Treat the date in A1 and the time in B1 as UTC values.
Once the manual test succeeds, replace the trigger with the required recurrence or event trigger.
For actual cloud-based data updates, retrieve records with the appropriate source connector and write them through Excel table actions or a purpose-built Office Script. That replaces the data-loading operation; it does not refresh the workbook’s existing Power Query queries.
Power BI Refresh for Excel-Based Models
Use Power BI when the required output is a refreshed report or semantic model rather than a refreshed Excel file.
Choose the refresh target based on where the updated data must live.
A Power BI refresh queries the model’s configured sources and updates the model in the service. It does not open the source workbook, refresh its worksheets, and save the file.
To prepare an Excel data model for this route:
- In Excel, configure the Power Query connections.
- In the Power Query Load To dialog, select
Add this data to the Data Model. - Publish the Excel data model as a Power BI semantic model.
- Configure the model’s data-source credentials.
- If its sources are on-premises, install and configure a supported gateway, and ensure that it is running.
- Use Refresh Now for a manual test, or Schedule Refresh for recurring updates.
- Inspect refresh history and verify a known changed source value in the report.
These refresh commands apply to supported data sources connected through Power Query or Power Pivot, under Microsoft’s Excel data model refresh requirements.
Confirm completion in Power BI refresh history rather than assuming that submitting the request means the refresh has finished.
Keep two additional boundaries in mind:
- Uploading local Excel workbooks to Power BI workspaces and configuring refresh for those uploaded workbooks is no longer supported. Publishing the data model is a different workflow.
- Structural changes made in Excel or Power Pivot, such as adding a measure or renaming a model column, are not copied into a published semantic model by an ordinary data refresh. Republish the model when those changes need to reach Power BI.
Troubleshoot Missing or Stale Excel Data
Match the failure to the operation that actually ran before changing credentials, adding delays, or rebuilding the flow.
| Symptom | Likely Cause | What to Change |
|---|---|---|
| Cloud script succeeds, but query results stay unchanged | Unsupported connection refresh through Office Scripts | Use desktop Excel or move the refresh target to Power BI |
| Diagnostic timestamp changes, but business data does not | Script execution was mistaken for source refresh | Validate a source-backed record or version |
| Flow writes to an unexpected worksheet | Relative worksheet reference or incorrect file selection | Use an explicit worksheet name and reselect the intended file |
| Desktop Excel opens and waits indefinitely | Credentials, privacy settings, or another dialog requires input | Resolve the prompt manually and retest the connection |
| Workbook saves before new data appears | Background refresh or an incomplete completion check | Validate the loaded result before saving |
| File is locked or changes conflict | Overlapping runs or concurrent editing | Serialize workbook access and close Excel after each run |
Diagnose Cloud Failures at the Action Level
Open the failed run and inspect the inputs and outputs of the Excel action. Confirm the selected file, script, and connection identity.
A flow can run under a different identity from the account you use interactively. That identity needs access to the workbook and, when the flow retrieves data directly, access to the upstream source as well.
If the workbook was moved or replaced, reselect it in the action rather than assuming its previous reference still identifies the intended file.
Diagnose Desktop Failures in Excel
Run the same workbook manually under the Windows account used by the desktop automation. This exposes problems hidden by an unattended run, including missing source paths, expired credentials, and provider-specific dialogs.
Keep Excel visible while diagnosing the failure. Once the connection, macro, validation, save, and close actions all work without intervention, retest using the intended execution mode.
Confirm and Maintain the Refresh Flow
Before enabling recurring runs, verify the result at the destination, not just in Power Automate’s run history.
Use this checklist:
- A known changed source record appears in the intended workbook or model.
- The saved workbook still contains the updated value after reopening.
- Formula results reflect the loaded data where recalculation is required.
- Failed validation prevents a success notification or downstream publication.
- Desktop Excel closes and releases the file after the run.
- Notifications distinguish a submitted refresh request from a verified refresh result.
Avoid a file-modified trigger on the workbook that the flow itself saves unless you have a condition that excludes the flow’s own changes. Otherwise, saving the refreshed workbook can start another run.
Start with a manually tested copy, verify an actual source change, and enable the scheduled trigger only after the saved result passes that check.
Frequently Asked Questions
Can I Create a Power Automate Flow to Refresh My PivotTable?
Yes: use desktop Excel when you need a workbook PivotTable refreshed. Refresh and validate the source data first, then have the desktop flow select the PivotTable and invoke PivotTable Analyze > Refresh, check its result, and save and close the workbook.
Why Does Power Query Refresh Take So Long?
Power Query refresh can be slow because of source latency, large transfers, expensive transformations, or several queries repeating the same work. Check whether filtering and column selection can occur at the source, and whether transformations preserve query folding where the connector supports it. Compare the manual Excel refresh with the automated run: if both are slow, changing the Power Automate trigger will not fix the underlying query.
Why Is Power Automate Excel Refresh So Difficult?
Excel automation crosses separate execution environments: the cloud connector, Office Scripts, desktop Excel, and sometimes Power BI. An operation available in interactive Excel may be unsupported or behave differently in a cloud-run script. Define the operation and its destination first, then test that operation independently before adding triggers, notifications, and downstream actions.
Can Power Automate update an Excel workbook?
Yes. A Power Automate flow can use the Excel Online (Business) Run script action to execute an Office Script against a workbook in OneDrive or a SharePoint site. Use consistent workbook and worksheet names so the flow can reference the intended workbook components.
