Forum Discussion

SargentSynergy's avatar
SargentSynergy
Copper Contributor
Jul 27, 2021
Solved

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 ...
  • SargentSynergy's avatar
    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. 

Resources