Forum Discussion
Office Scripts - Working With Multiple Worksheets
- Jul 27, 2021
I figured this out... all you have to do is declare a different variable name for the next workbook. In the first block of code, which is in my original message, the variable is called "selectedsheet" and the statement looks like this: "let selectedSheet = workbook.getWorksheet("Issues");"
What I did for the next worksheet is this: "let sheetproblems = workbook.getWorksheet("problems")" and followed up with the rest of the items.The way I figured this out was to open a new Excel sheet and actually record a new script by bolding the text in cells on two separate worksheets. Then I just looked at the code that was automatically generated to see how it handled switching worksheets.
I hope someone finds this information useful in the future.
Is it possible to run multiple Office Scripts in parallel on the same workbook?
We need to reduce the execution time of the Power Automate flow to improve agent response times.
How can we avoid save conflict errors when running multiple Office Scripts simultaneously on the same workbook?
rahulp35 I have scripts that are manually run by multiple users potentially simultaneously using a button and scripts run from Power Automate flow and haven't had any issues yet, but maybe haven't pushed the boudaries much either. That said, since you are in control of what they are doing, can't you just make sure they aren't changing/saving the exact same data/cells? As you say, they need to run "in parallel" and shouldn't intersect and you should be fine. but if the write of one overlaps with either the read or write of another then you will likely have race conditions happening.
- rahulp35Aug 26, 2026Copper Contributor
Thank you for your reply,
I am trying to run 4 different office script on 4 different sheets in same file.
so, no script is overlapping on each other cell, issue is during saving file I guess 2 of the script are trying to save file at same time.