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

Notifications

Announcements

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard