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 / Office Script getRange...
Power Automate
Answered

Office Script getRange Error: Cannot read property 'getRange' of undefined

(0) ShareShare
ReportReport
Posted on by 27

Hello, 

 

I am building a Cloud flow that runs an Office Script on each .xlsx file in a folder. When I run the script within a particular .xlsx instance in Excel Online, the script works perfectly. But, when using the 'Run Script' Excel connection/action in PA, I get the following error: "\nRuntime error: Line [line number]: Cannot read property 'getRange' of undefined\r" 

 

What am I doing wrong? Is this a relative reference (that is disallowed in Power Automate)? Or something else? 

 

 

function main(workbook: ExcelScript.Workbook) {
// ... 

let _3__Data_Types_Used = workbook.getWorksheet("3. Data Types Used");
// Delete row 1 on _3__Data_Types_Used
_3__Data_Types_Used.getRange("1:1").delete(ExcelScript.DeleteShiftDirection.up);
	
// ... 
}

 

 

Ultimately, I am not committed to any syntax or strategy--I just want to successfully delete Row 1!

 

Categories:
  • Verified answer
    MichelleRanMSFT Profile Picture
    Microsoft Employee on at

    Hey @cnjahu, thanks for your question! The script you shared works fine for me in Power Automate. From the error you're encountering, it looks like _3_Data_Types_Used is undefined, which likely means the worksheet you're trying to get doesn't exist in the workbook. You've mentioned this script works fine if you run it in Excel Online - can you double-check that the workbook file you've selected in Power Automate contains the selected sheet, with an exact match to the name? Additionally, does any previous step in your flow modify the workbook?

  • CU20080748-1 Profile Picture
    27 on at

    Hey @MichelleRanMSFT, just following up to say thanks for helping solve my problem! 

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 307 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 289

#3
Henil Profile Picture

Henil 127

Last 30 days Overall leaderboard