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 / Power Automate retturn...
Power Automate
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?

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

    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

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!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 862

#2
Valantis Profile Picture

Valantis 738

#3
Haque Profile Picture

Haque 553

Last 30 days Overall leaderboard