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 / Excel Office Script Ru...
Power Automate
Unanswered

Excel Office Script Runs in Power Automate Without Error, But Script Doesn't Actually Run. Script works from Excel Online

(0) ShareShare
ReportReport
Posted on by 10

I've created a cloud power automate flow to listen for a new Excel file in a OneDrive folder, wait 10 seconds, run an Excel Office Script, wait 10 seconds, then upload the file to an FTP. Please see the flow here:

 

Screenshot 2022-12-28 at 11.57.12 AM.png

 

When a new file is uploaded to OneDrive, the flow runs without error:

Screenshot 2022-12-28 at 11.56.46 AM.png

 

Unfortunately, the Office Script did NOT run. I can, however, open the Excel file from OneDrive in a browser, choose the Automate tab, and then run the Office Script and it DOES run from within Excel Online. It just doesn't run when I try to run the script from Power Automate. What am I doing wrong? Thanks!

Categories:
I have the same question (0)
  • lbendlin Profile Picture
    8,474 Super User 2025 Season 2 on at

    When that file is uploaded does it actually contain the script? Or is the script stored elsewhere and would have to be referenced differently?

  • mbial Profile Picture
    10 on at

    Thanks for your reply. I believe Office Scripts for Excel are stored in the user's OneDrive account. When I open these uploaded files in OneDrive in the browser, I'm able to select the automate tab, choose the script I want to run, and everything is perfect. Not sure how that would differ from me running it the way I've described above. Thanks again!

  • lbendlin Profile Picture
    8,474 Super User 2025 Season 2 on at

    Have you tried to use this "official" template ?

     

    Microsoft Power Automate

    lbendlin_0-1672270158990.png

     

    If you don't mind asking - what is the script supposed to do?  Can you verify somehow that it ran?

    I tried a couple of scripts in my OneDrive and these work as expected.

  • grantjenkins Profile Picture
    11,063 Moderator on at

    I'm assuming the file you created should be updated within your Office Script. If so, then it might be working, but the content you're using in your Create file is from the file content when it was first created, not from after the updates.

     

    After running your script, add a Get file content to get the latest (updated) content of the file, and use that content in your Create file action.


    ----------------------------------------------------------------------
    If I've answered your question, please mark the post as Solved.
    If you like my response, please consider giving it a Thumbs Up.

  • mbial Profile Picture
    10 on at

    Thanks for your feedback. Unfortunately, this still isn't working, so I've simplified the entire flow to 3 basic steps:

    Screenshot 2022-12-29 at 11.36.06 AM.png

    The flow completes successfully, but the script didn't actually do anything (even though the script step shows as successfully completed). We're no longer hung up on the next step of file creation, the focus is purely on successfully running the script on the new file. Any other ideas? Thanks again!

  • lbendlin Profile Picture
    8,474 Super User 2025 Season 2 on at

    "File" has to be a file identifier, not a file name. As @grantjenkins mentions you need to retrieve the identifier of the newly uploaded file and then use that for running the script.

  • mbial Profile Picture
    10 on at

    Same result using 'File Identifier'. Power automate runs successfully, but script doesn't change Excel file. The Office Script simply copies a sheet and pastes it to another sheet in the same excel file. I also tried using the following template with the same result:

    Run an Office Script on Excel workbooks added to a OneDrive folder 

  • grantjenkins Profile Picture
    11,063 Moderator on at

    @mbial As @lbendlin mentioned, you should be using File identifier in your Run script which will ensure it's the exact file that was just created. This should work as expected. Below shows what you should be using for File.

     

    grantjenkins_0-1672361395175.png

     

    Are you able to show your actual Office Script code to see if there's something in there that's causing the issue.

  • mbial Profile Picture
    10 on at

    Yes @grantjenkins as I mentioned I have already tried this with File Identifier and the result is the same. I've included the office script below. Again, the office script runs properly when I run it form within Excel Online. Thank you so much!

     

    function main(workbook: ExcelScript.Workbook) {
    let for_NetSuite = workbook.getWorksheet("For NetSuite");
    // Set number format for range C:C on for_NetSuite
    for_NetSuite.getRange("C:C").setNumberFormatLocal("m/d/yyyy");
    // Set number format for range P:P on for_NetSuite
    for_NetSuite.getRange("P:P").setNumberFormatLocal("@");
    let selectedSheet = workbook.getActiveWorksheet();
    // Paste to all cells on for_NetSuite from all cells on selectedSheet
    for_NetSuite.getRange().copyFrom(selectedSheet.getRange(), ExcelScript.RangeCopyType.values, false, false);
    }

     

     

  • lbendlin Profile Picture
    8,474 Super User 2025 Season 2 on at
    let selectedSheet = workbook.getActiveWorksheet();

    I don't think that will do anything useful in automated mode. As a result you may be copying stuff from the sheet to itself.  Better use absolute sheet addressing by name.

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 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard