Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Unanswered

Power Automate retturn Office Script errors when using setName() with variable and getUsedRange()

(0) ShareShare
ReportReport
Posted on by

Hi All!

So I’m facing strange issue, I have prepared Office Scripts for Excel and when I run them directly in Excel everything works but as son as I want to run them via Power Automate I'm getting errors.

 

Issue 1

This works fine:

 

workbook.getWorksheet("Sheet1").setName("SampleName");

 

 This doesn't work:

 

let SampleVariable = "SampleName";
workbook.getWorksheet("Sheet1").setName(SampleVariable);

 

and return error:

 

Błąd skryptu Office JS: Line 35: {"message":"The argument is invalid or missing or has an incorrect format.","code":"InvalidArgument","type":"Worksheet","method":"setName","line":34}

 

As mentioned when running scripts directly in Excel both methods works just fine.

 

Issue 2
This code works fine when run in Excel but doesn't work in Power Automate:

 

let selectedSheet = workbook.getWorksheet("SampleName");
let SampleRng = selectedSheet.getUsedRange();

 

and return error:

 

Błąd czasu wykonywania: Line 59: Cannot read properties of undefined (reading 'getUsedRange')

 

 

Anyone have a workaround?

  • MichelleRanMSFT Profile Picture
    Microsoft Employee on at
    Re: Power Automate retturn Office Script errors when using setName() with variable and getUsedRange()

    Hi @krzycho - sorry to hear you're running into this issue! I tried running the code snippets you shared through Power Automate and they worked fine for me. To help us troubleshoot better, would you be able to share (1) your entire script, and (2) your flow configuration, with sensitive data removed as needed?

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

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >