Copy Data Between Excel Workbooks with Power Automate and Office Scripts
Question details
Automate the transfer of data between separate Excel workbooks when an Office Script cannot record cross-workbook actions.

- 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.
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.
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.
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.
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.
In Power Automate, create a cloud flow with your preferred trigger. Add Excel Online (Business) > Run script, select the source workbook, and choose ReadData.
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.
Select Save and Test in Power Automate, run the flow, and open the destination workbook to check the cells starting at A1.

Transfer table rows with Excel connector actions
Use connector actions when the source and destination data are already organized as Excel tables.
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.

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.




