Power Query Problems

Can Office Scripts Refresh Excel Queries or Use Refresh All?

Nimra MalikNimra Malik Nov 10, 2026 868 views

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.

Can Office Scripts Refresh Excel Queries or Use Refresh All?
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Press the Alt + F11 keys simultaneously in your desktop Excel application to open the Microsoft Visual Basic for Applications window.

2
Insert a New Module

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.

3
Enter the Refresh Code

Paste the following code into the module window: Sub RefreshAllQueries() ThisWorkbook.RefreshAll End Sub

4
Run the Macro

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.

Use VBA as a Workaround in Desktop Excel
Desktop Only Feature: VBA macros are exclusively supported in desktop versions of Excel and will not function in Excel on the web.
Free Microsoft Office alternative

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. 1. Download and Install WPS Office: Visit the official WPS website, download the free installer, and complete the quick installation process.
  2. 2. Open Your Spreadsheet: Launch WPS Spreadsheet and open your existing Excel files directly, without worrying about formatting loss.
  3. 3. Utilize Macros: Navigate to the Tools tab and select Macros to write or execute your VBA scripts for data automation.
Fully compatible with Microsoft Excel (.xlsx) and macro (.xlsm) formatsBuilt-in VBA support for advanced desktop automationFree, lightweight, and incredibly easy to installFamiliar ribbon interface ensures zero learning curve
microsoft office alternative - wps office

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'.