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

Community site session details

Session Id :
Power Automate - Building Flows
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!

 

I have the same question (0)
  • Verified answer
    MichelleRanMSFT Profile Picture
    Microsoft Employee on at
    Re: Office Script getRange Error: Cannot read property 'getRange' of undefined

    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
    Re: Office Script getRange Error: Cannot read property 'getRange' of undefined

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 647 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 350 Moderator

#3
developerAJ Profile Picture

developerAJ 256

Last 30 days Overall leaderboard