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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Error Message: We were...
Power Automate
Unanswered

Error Message: We were unable to run the script

(0) ShareShare
ReportReport
Posted on by 2
  Hi, 
 
I am attempting to run a PowerAutomate Flow and got the following error:

"message"
"We were unable to run the script. Please try again.\nRuntime error: Line 8: Cannot read properties of undefined (reading 'delete')\r\nclientRequestId: 027b7552-7d6f-47cd-82ec-5f01590efbe4"
 
Below is the code for the script:
function main(workbook: ExcelScript.Workbook
SheetsToDeleteArray<string> = [],
)
{
    // for each of the worksheets in the array
    for (let worksheet of SheetsToDelete) {
      //delete the worksheet
      workbook.getWorksheet (worksheet).delete();
}

 //get current worksheets in workbook
  let sheets = workbook.getWorksheets();
  let names = sheets.map((sheet) => sheet.getName());

  //return the number of sheets left
  return(names.length)

}
 
Any thoughts as to why this is not functioning?

Thanks,
Rich

Categories:
I have the same question (0)
  • v-bofeng-msft Profile Picture
    Microsoft Employee on at

    Hi @RichardC ,

     

    Pease try

     

    let sheet = workbook.getWorksheet (worksheet)[0];
    sheet.delete();​

     

     

    vbofengmsft_0-1683077035310.png

     

    Best Regards,
    Bof

     

  • RichardC Profile Picture
    2 on at
    Hi, Thanks Bof, 

    I got the following error:
    See line 8, column 11: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 557

#2
Valantis Profile Picture

Valantis 328

#3
David_MA Profile Picture

David_MA 264 Super User 2026 Season 1

Last 30 days Overall leaderboard