Forum Discussion
Office Scripts - Working With Multiple Worksheets
I'm trying to write a script which writes data, via Power Automate, to multiple worksheets inside one workbook. I'm new to office scripts, so I'm not sure if I can do this in one script or if I have to do a separate script for each worksheet.
Here is an example of the code:
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.
4 Replies
- rahulp35Occasional Reader
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?
- rahulp35Occasional Reader
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?
- SargentSynergyTin Contributor
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.
- Sarah_NgueCopper Contributor
Thanks for your reviewSargentSynergy. I´ve had the same issue and your response helps me lot 🙂 .