web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Office script for mult...
Power Automate
Unanswered

Office script for multiple worksheets

(0) ShareShare
ReportReport
Posted on by 25

I am new to office scripting so I may be a little off base but here goes:

 

As with so many, I need to create tables in Excel workbooks that are received via email.  The added challenge is that the workbooks may have one to six worksheets and I need to create a table in all worksheets present.  The one thing working in our favor is that there are only 6 sheet names for the users to select from.  For the sake of simplicity lets say the sheet names are red, blue, green, yellow, black and white. One workbook may contain the worksheets red and white, while another workbook may contain all 6 and another only contain green.

 

The Microsoft documentation seems to be saying that using a variable for the sheet names in scripting.  But the only options I have seen for selecting a sheet are to select the first sheet or the active sheet.  

 

I need some way to select each sheet that is present.  Does anyone have a solution that will do this?

Categories:
I have the same question (0)
  • Yutao Huang Profile Picture
    Microsoft Employee on at

    Do you need to do exactly the same thing on every worksheet present in that workbook?

     

    If yes, something like this may help:

    function main(workbook: ExcelScript.Workbook)
    {
     workbook.getWorksheets().forEach(sheet => {
     // Do stuff to the sheet
     });
    }

     

    But if you need to do different things on different sheets, you may need to do something like this:

    function main(workbook: ExcelScript.Workbook)
    {
     let redSheet = workbook.getWorksheet("red");
     // Do stuff on redSheet
    
     let blueSheet = workbook.getWorksheet("blue");
     // Do stuff on blueSheet
    
     let greenSheet = workbook.getWorksheet("green");
     // Do stuff on greenSheet
    
     // ...
    }

     

  • FeierCiprian Profile Picture
    20 on at

    This Office script will help you convert all sheets into table once you run it from Power Automate
    Screenshot 2023-10-02 155928.jpg

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard