Hello,
I have a power automate flow which runs office scripts in excel. The first script copies and returns certain contents of the file and first occurring date in the file and dynamically allocates these returns to another script to either paste the data in the correct place chronologically using the first occurring date or it pastes the data at the end of the existing data. It works perfectly fine for files below 5MB but the issue I am facing is that the copy script will only run on smaller files because of the restrictions with excel scripts and the range functions. I have read that if I am able to split the data into chunks or there are some ways around this limitation but I can't find a clear guide how to do it or anywhere that confirms this is even possible.
I thought about implementing a part into the copy function which first determines how big the file is (how many rows), then divides it by how many max rows we are allowed to deal with at a time and then loops the copying process for however many chunks are needed and returns multiple copied chunks. Then in the paste function i wanted to loop the pasting process for however many chunks were returned and paste them in order. An issue I see with this solution is that currently in my power automate flow I have certain boxes where I dynamically allocate the copied data, and there is no way to determine how many chunks there will be, therefore I can't assign what the second script is pasting.
Does anyone know if for my case it is possible to modify my script or PA flow so that it works for larger files or where I can find a guide on how to do so? Thanks in advance.
This is the copying script:
and this is the pasting script:
Hi @cecilia123 ,
I don't see any apparent error in the script description. You can change the retry policy by clicking in settings:
And then changing this dropdown to 'None':
This change must limit your scripts to run only once, and then fail (if it times out).
Let me know if it works!
Hi @rzaneti ,
Thanks so much for the reply! Just to clarify this is how I will adjust my scripts and flow:
1. I will declare a variable called "rows pasted" at the beginning of the flow.
2. I will add another short office script that can return the total rows there are in the file I am copying from and run it in PA.
3. I will add a do until function for when the "rows pasted" is equal to or greater than the "total rows". Inside the do until function:
3a. I will run my copy script which now copies 10 000 rows at a time to make sure it doesn't take more than 120s.
3b. I will paste the rows copied by the copy script after each other into the new file. If the "rows pasted" is at 0, I will make sure to check for when the first date occurs so I can paste the first chunk into the correct place.
3c. I will increment the "rows pasted" 10000 rows so I know where to copy and paste the next chunk and the do until loop will function properly.
I've adjusted my scripts and am trying to run variations of what I just laid out but I am still running into issues. It might take a lot of testing to get right but do you see any issues with the above logic? Also, each test runs for about 10 minutes before it times out and fails, do you know how to make the tests time out sooner if they are failing so that the testing takes less time?
Thanks again!
Hi @cecilia123 ,
Ideally, the file size should not affect your Run Script action performance. There is a limitation of 5mb for requests/responses related to Office Scripts, but it is not directly impacted by the file size. However, a known limitation is the duration of your script run: it must be lower than 120 seconds.
Your idea to break the table records in chunks is very good, and it can work. In the past, had a similar problem and used a similar approach, where I've allocated the Run script into a Do until loop. In my Office Script, I returned to PA both the total quantity of rows and the number of the currently last accessed row, so I could stay in the loop until all rows were affected. This approach is good to handle spreadsheets with different "occupied cells" size.
For your use case, this same approach seems to work. Let me know if the description above makes sense and, if you are confused on how to put it in practice, I can come back to you on Monday with a step-by-step on how to implement this Run Script/Do until integration.
Also, for any users starting in integrating Power Automate with Office Scripts that find this thread, I'm sharing some articles that I wrote about it:
- Office Scripts vs. VBA: http://digitalmill.net/2023/06/10/office-scripts-the-new-vba/
- Getting started with Office Scripts: http://digitalmill.net/2023/06/19/get-started-with-office-scripts/
- Variables in Office Scripts: http://digitalmill.net/2024/06/26/variables-in-office-scripts/
- Accessing Excel ranges with Office Scripts: http://digitalmill.net/2023/09/01/accessing-excel-ranges-with-power-automate/
- Sending values from PA to Excel with Office Scripts: http://digitalmill.net/2024/01/17/sending-values-from-power-automate-to-excel-with-office-scripts/
Let me know if it works for you or if you need any additional help!
-------------------------------------------------------------------------
If this is the answer for your question, please mark the post as Solved.
If this answer helps you in any way, please give it a like.
http://digitalmill.net/
https://www.linkedin.com/in/raphael-haus-zaneti/
Michael E. Gernaey
566
Super User 2025 Season 1
David_MA
516
Super User 2025 Season 1
stampcoin
492