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 with Of...
Power Automate
Unanswered

Power Automate with Office Script: Run Script and Create worksheet wont work together

(0) ShareShare
ReportReport
Posted on by 14

Hi,

I have a fairly long flow with 2 critical elements:1

1) Create woksheet (adds worksheet to an Excel file) - works

2) Run a script - inserts a file into the sheet create above - works, but only if I create the worksheet manually before running the flow

 

1 and 2 each work on their own. However I am unable to get the script to run on a worksheet created by the flow. The error I get implies that the worksheet doesn't exist:

 
"message": "We were unable to run the script. Please try again.\nRuntime error: Line 4: Cannot read properties of undefined (reading 'addImage')\r\nclientRequestId: 00b51c59-0d6f-4c33-a35c-4b2364a82f71",
  "logs": []
 
Here is the full script:
function main(workbook: ExcelScript.Workbook, sheetName: string, address: string, base64ImageString: string) {
  let sheet = workbook.getWorksheet(sheetName);
  let range = sheet.getRange(address);
  let image = sheet.addImage(base64ImageString);
  image.setTop(range.getTop());
  image.setLeft(range.getLeft());
}
 
Here is the contents of the flow:
ryan666_0-1687872470000.png

 

The sheet name is the word "Image" with a counter. So the sheet names are Image1, Image2, Image 3, etc.

 

Categories:
I have the same question (0)
  • rzaneti Profile Picture
    4,330 Super User 2025 Season 2 on at

    Hi @ryan666 ,

     

    I have this same issue in some flows. Apparently this is one of the limitations of the Excel connector: sometimes the file can be locked for update/delete for up to 6 minutes. It does not occur every flow run (at least for me) and as far as I remember, it never got locked for more than 1 minute. You can check the limitations here : https://learn.microsoft.com/en-us/connectors/excelonlinebusiness/#known-issues-and-limitations-with-actions

     

    There is also this thread that discusses this "file locking" issue among other topics: https://powerusers.microsoft.com/t5/General-Power-Automate/Excel-connector-to-update-a-row-and-save-as-another-file-failed/td-p/271507#:~:text=An%20Excel%20file%20may%20be,connections%20and%20possible%20data%20inconsistency

     

  • ryan666 Profile Picture
    14 on at

    I found that if I put a delay between the worksheet creation and running the script, suddenly it works.

    However the delay is not practical for my purpose. 

    Is there a way around this?

     

    Smallest delay that works looks to be about 25 sec. The delay is inside a loop and not a practical solution unfortunately.

    ryan666_0-1687877721912.png

     

     

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
David_MA Profile Picture

David_MA 245 Super User 2025 Season 2

#2
Expiscornovus Profile Picture

Expiscornovus 207 Most Valuable Professional

#3
trice602 Profile Picture

trice602 185 Super User 2025 Season 2

Last 30 days Overall leaderboard