Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 81ClfC80H6MwGMhL1CKV5V
Power Automate - Building Flows
Unanswered

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

Like (0) ShareShare
ReportReport
Posted on 28 Dec 2022 17:04:14 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!

  • mbial Profile Picture
    10 on 06 Jan 2023 at 19:30:21
    Re: Excel Office Script Runs in Power Automate Without Error, But Script Doesn't Actually Run. Script works from Excel Online

    Thanks for all the feedback. The issue was the line in the script that @lbendlin noted. The script worked properly when I was directly interacting with the spreadsheet in the browser, but because it was looking for the ActiveWorksheet, there was no sheet to select (the file wasn't open). I explicitly referenced the name of the sheet I was trying to copy from, and now everything is resolved. Thanks for your help!!

  • lbendlin Profile Picture
    7,801 Super User 2025 Season 1 on 30 Dec 2022 at 18:14:19
    Re: Excel Office Script Runs in Power Automate Without Error, But Script Doesn't Actually Run. Script works from Excel Online
    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.

  • mbial Profile Picture
    10 on 30 Dec 2022 at 03:41:39
    Re: Excel Office Script Runs in Power Automate Without Error, But Script Doesn't Actually Run. Script works from Excel Online

    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);
    }

     

     

  • grantjenkins Profile Picture
    11,059 Super User 2025 Season 1 on 30 Dec 2022 at 00:52:58
    Re: Excel Office Script Runs in Power Automate Without Error, But Script Doesn't Actually Run. Script works from Excel Online

    @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 29 Dec 2022 at 21:53:54
    Re: Excel Office Script Runs in Power Automate Without Error, But Script Doesn't Actually Run. Script works from Excel Online

    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 

  • lbendlin Profile Picture
    7,801 Super User 2025 Season 1 on 29 Dec 2022 at 19:36:46
    Re: Excel Office Script Runs in Power Automate Without Error, But Script Doesn't Actually Run. Script works from Excel Online

    "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 29 Dec 2022 at 16:38:31
    Re: Excel Office Script Runs in Power Automate Without Error, But Script Doesn't Actually Run. Script works from Excel Online

    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!

  • grantjenkins Profile Picture
    11,059 Super User 2025 Season 1 on 29 Dec 2022 at 00:43:30
    Re: Excel Office Script Runs in Power Automate Without Error, But Script Doesn't Actually Run. Script works from Excel Online

    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.

  • lbendlin Profile Picture
    7,801 Super User 2025 Season 1 on 28 Dec 2022 at 23:29:20
    Re: Excel Office Script Runs in Power Automate Without Error, But Script Doesn't Actually Run. Script works from Excel Online

    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.

  • mbial Profile Picture
    10 on 28 Dec 2022 at 22:44:29
    Re: Excel Office Script Runs in Power Automate Without Error, But Script Doesn't Actually Run. Script works from Excel Online

    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!

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Building Flows

Overall leaderboard