Can Office Scripts Refresh Excel Queries or Use Refresh All?
Question details
The user wants to know if it is possible to automate the refreshing of Power Query connections or trigger the Refresh All function using Office Scripts in Excel.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Attempting to automate the refreshing of external data connections and Power Queries using Office Scripts for workflow automation.
- Observed behavior
- Office Scripts cannot trigger the Refresh All function or refresh external data connections because the current API does not support these actions.
Verify whether you are using Excel on the web or Excel for Desktop, as the alternative VBA workaround is only applicable to the desktop version.
Use VBA as a Workaround in Desktop Excel
Since Office Scripts lack the API to refresh queries, using a VBA macro is the most effective way to automate the 'Refresh All' action in the desktop environment.
While Office Scripts are designed primarily for Excel on the web and support ranges, tables, and formatting, they cannot interact with external data connections. VBA (Visual Basic for Applications) remains the standard tool for this task on desktop.
Press the Alt + F11 keys simultaneously in your desktop Excel application to open the Microsoft Visual Basic for Applications window.
In the top menu of the VBA editor, click on Insert, and then select Module from the dropdown list to create a blank script window.
Paste the following code into the module window: Sub RefreshAllQueries() ThisWorkbook.RefreshAll End Sub
Press F5 while inside the code window, or go back to Excel, press Alt + F8, select RefreshAllQueries, and click Run to update all your data connections.

Manually Refresh Queries via the Ribbon
If you cannot use VBA and Office Scripts do not work, you can always rely on the built-in manual refresh button to update your dataset.
Manage Spreadsheets Efficiently with WPS Office
If you frequently encounter limitations with cloud scripting, consider switching to WPS Office. It is a powerful, lightweight suite that fully supports desktop macros (VBA) for automating your data tasks seamlessly.
- 1. Download and Install WPS Office: Visit the official WPS website, download the free installer, and complete the quick installation process.
- 2. Open Your Spreadsheet: Launch WPS Spreadsheet and open your existing Excel files directly, without worrying about formatting loss.
- 3. Utilize Macros: Navigate to the Tools tab and select Macros to write or execute your VBA scripts for data automation.

Frequently Asked Questions
Why doesn't the Office Scripts API support Refresh All?
Office Scripts were designed to manipulate grid elements like ranges, tables, and formatting securely on the web. Interacting with external data connections and Power Query involves complex security and backend integrations that Microsoft has not yet exposed in the Office Scripts API.
Can I use Office Scripts to refresh a specific PivotTable?
Yes. While you cannot refresh external Power Queries, Office Scripts can refresh PivotTables connected to internal worksheet data by calling the refresh() method on the specific PivotTable object.
Is there a way to automate Power Query refreshes without using scripts or macros?
Yes. You can configure connection properties in Excel to refresh automatically. Go to Data > Queries & Connections, right-click your connection, select Properties, and check options like 'Refresh data when opening the file' or 'Refresh every X minutes'.




