Data Import & Export

Copy Data Between Excel Workbooks with Power Automate and Office Scripts

Nimra MalikNimra Malik Dec 2, 2026 869 views

Question details

Automate the transfer of data between separate Excel workbooks when an Office Script cannot record cross-workbook actions.

Copy Data Between Excel Workbooks with Power Automate and Office Scripts
Product
Microsoft Excel, Office Scripts, and Power Automate
Device & OS
not provided
Scenario
A user wants to move data from a source workbook to a destination workbook as part of an automated flow.
Observed behavior
An Office Script operates on the workbook passed to it, rather than recording actions across both workbooks.
Before you start

Store both workbooks in OneDrive for Business or SharePoint and confirm that your account can access them through the Excel Online (Business) connector. Identify the source range and destination cells, or create named tables with matching columns if you plan to use table actions.

Solution 1Recommended

Run separate Office Scripts for the source and destination workbooks

Use this approach when you need to transfer a specific range rather than rows from a named table.

Each Run script action works with its selected workbook. The first script returns the source values to the flow, and the second receives those values and writes them to the destination.

This example copies cell values, not formatting or formulas. It overwrites destination cells starting at A1.

1
Create the source script

Open the source workbook in Excel for the web, select Automate > New Script, and save a script named ReadData: function main(workbook: ExcelScript.Workbook): string { return JSON.stringify(workbook.getWorksheet('Sheet1').getRange('A1:C10').getValues()); } Change the sheet name and range to match your source.

2
Create the destination script

In the destination workbook, select Automate > New Script and save a script named WriteData: function main(workbook: ExcelScript.Workbook, dataJson: string) { const data = JSON.parse(dataJson) as (string | number | boolean)[][]; workbook.getWorksheet('Sheet1').getRange('A1').getResizedRange(data.length - 1, data[0].length - 1).setValues(data); } Change the sheet name and starting cell as needed.

3
Add the source action to a flow

In Power Automate, create a cloud flow with your preferred trigger. Add Excel Online (Business) > Run script, select the source workbook, and choose ReadData.

4
Add the destination action

Add a second Excel Online (Business) > Run script action, select the destination workbook, and choose WriteData. In the dataJson parameter, select the result output from the ReadData action in dynamic content.

5
Test the transfer

Select Save and Test in Power Automate, run the flow, and open the destination workbook to check the cells starting at A1.

Run separate Office Scripts for the source and destination workbooks
Check the destination range: Make sure the destination has enough space for the returned rectangular range. Existing values in that area will be replaced.
Free Microsoft Office alternative

Work with Excel Workbooks in WPS Spreadsheet

WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Excel files. Its format compatibility makes it easier to move existing workbooks into WPS Spreadsheet, although it does not replace Power Automate or Office Scripts.

Open and edit Microsoft Excel XLSX workbooksCopy and organize data between workbooks in WPS SpreadsheetUse a familiar spreadsheet interface for everyday tasksAccess a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Can one Office Script directly record actions in two workbooks?

An Office Script operates on the workbook passed to it. To transfer data between files, use Power Automate to run a source script and pass its result to a destination script.

Do both workbooks need to be stored online?

For the Excel Online (Business) actions described here, store the files in an accessible OneDrive for Business or SharePoint location and select those locations in each flow action.

Will the script transfer formulas and formatting?

The example uses getValues and setValues, so it transfers cell values rather than formulas or formatting. A different script is needed if those elements must also be copied.

Why are duplicate rows appearing in the destination table?

Add a row into a table appends rows each time the flow runs. Add a check for existing records or filter the source rows if you need to avoid adding the same data again.