logo
search
VBA & Macro Problems

How to Return Multiple Excel Office Script Values to Power Automate

Jason MillerJason Miller Oct 15, 2026 870 views

Question details

The user needs to output multiple calculated values from an Excel Office Script so they can be selected individually as dynamic content in a Power Automate flow.

How to Return Multiple Excel Office Script Values to Power Automate
Product
Excel, Power Automate
Device & OS
not provided
Scenario
A user is running an Excel Office Script via Power Automate and wants to use multiple distinct results (like CountA, CountB) in subsequent steps such as Compose actions or Microsoft Teams messages.
Observed behavior
When the script returns a single value or generic variable, Power Automate only displays a single generic result field, making it difficult to extract and use the individual calculated values.
Before you start

Ensure your Excel file is saved in OneDrive for Business or SharePoint, and you have adequate Microsoft 365 permissions to edit Office Scripts and modify Power Automate flows.

Solution 1Recommended

Return an Object with Named Properties

Modify your Office Script to return a specific interface or object containing all the values you need. This allows Power Automate to parse the output into separate dynamic content fields.

By default, returning a primitive value from an Office Script results in a generic output in Power Automate. To access multiple distinct values, you must define an interface that describes your data structure and ensure your main function returns an object matching that interface.

1
Define an Interface

Open your Excel workbook on the web, go to the Automate tab, and edit your script. At the end of the script, define an interface for your outputs, for example: interface ScriptResult { CountA: number; CountB: number; CountC: number; }

2
Update the Main Function Signature

Modify the main function to declare that it will return this new interface. Change the function definition to: function main(workbook: ExcelScript.Workbook): ScriptResult {

3
Return the Object

At the very end of your main function, return an object containing the calculated variables mapped to the interface properties: return { CountA: countA, CountB: countB, CountC: countC };

4
Update Power Automate Flow

Save the script and open your Power Automate flow. If the 'Run script' action is already present, you may need to delete and re-add it to refresh the schema. The properties CountA, CountB, and CountC will now be available as distinct items in the Dynamic Content menu.

5
Use Expressions if Needed

If the dynamic content does not appear immediately, you can reference the variables manually using an expression in your Compose or Teams action, such as body('Run_script')?['CountA'] or outputs('Run_script')?['body/CountA'].

Return an Object with Named Properties
Dynamic Content Accessibility: Once the object is correctly returned, Power Automate automatically generates tokens for these properties, saving you from writing custom JSON parsing steps.
Free Microsoft Office alternative

Automate Your Spreadsheets with WPS Office

While Power Automate and Office Scripts offer cloud-based automation, they require complex Microsoft 365 setups. If you want a lightweight, highly compatible alternative for automating tasks locally, WPS Office provides excellent built-in support for JS Macros and VBA.

  1. 1. Download WPS Office: Visit the official WPS Office website and download the free spreadsheet software.
  2. 2. Open Your Excel File: Launch WPS Spreadsheets and open your existing .xlsx or .xlsm files without losing formatting.
  3. 3. Explore WPS Macros: Navigate to the Tools tab to access the built-in Macro Editor for automating your local workflow using JavaScript or VBA.
Highly compatible with Microsoft Excel formats including .xlsx and .xlsmRobust built-in support for JavaScript Macros (WPS JS API) and VBALightweight application that uses fewer system resourcesFree and intuitive interface for seamless transition from Microsoft Office
microsoft office alternative - wps office

Frequently Asked Questions

Why does my Office Script only show 'result' in Power Automate dynamic content?

This happens when your script returns a single primitive value (like a string, number, or array) without named keys. To get distinct dynamic content fields, you must define an interface and return a JSON object with named properties.

How do I manually reference a property from an Office Script output in a Power Automate expression?

You can use the expression function body() or outputs() followed by the property key. For example, to get a property named CountB from a script action named 'Run script', use the expression body('Run_script')?['CountB'].

Can I use Excel script variables directly in Teams messages using Power Automate?

Yes. Once your Office Script returns an object with named properties, you can select those specific properties from the dynamic content menu and insert them directly into the 'Post message in a chat or channel' action for Microsoft Teams.