Call scripts from a manual Power Automate flow
This tutorial teaches you how to run an Office Script for Excel on the web through Power Automate. You'll make a script that updates the values of two cells with the current time. You'll then connect that script to a manually triggered Power Automate flow, so that the script is run whenever a button in Power Automate is selected. Once you understand the basic pattern, you can expand the flow to include other applications and automate more of your daily workflow.
Before starting this tutorial, you'll need access to the following:
- Power Automate.
- Excel on the web.
- A Microsoft 365 commercial or EDU plan that includes Office Scripts.
Prepare the workbook
Power Automate shouldn't use relative references like
Workbook.getActiveWorksheet to access workbook components. So, we need a workbook and worksheet with consistent names that Power Automate can reference.
Create a new workbook named MyWorkbook.
In the MyWorkbook workbook, create a worksheet called TutorialWorksheet.
Create an Office Script
Go to the Automate tab and select All Scripts.
Select New Script.
Replace the default script with the following script. This script adds the current date and time to the first two cells of the TutorialWorksheet worksheet.
Rename the script to Set date and time. Select the script name to change it.
Save the script by selecting Save Script.
Create an automated workflow with Power Automate
Sign in to the Power Automate site.
In the menu that's displayed on the left side of the screen, select Create. This brings you to list of ways to create new workflows.
In the Start from blank section, select Instant flow. This creates a manually activated workflow.
In the dialog window that appears, enter a name for your flow in the Flow name text box, select Manually trigger a flow from the list of options under Choose how to trigger the flow, and then select Create.
Note that a manually triggered flow is just one of many types of flows. In the next tutorial, you'll make a flow that automatically runs when you receive an email.
Select New step.
Select the Standard tab, then select Excel Online (Business).
Under Actions, select Run script.
Next, you'll select the workbook and script to use in the flow step. For the tutorial, you'll use the workbook you created in your OneDrive, but you could use any workbook in a OneDrive or SharePoint site. Specify the following settings for the Run script connector:
- Location: OneDrive for Business
- Document Library: OneDrive
- File: MyWorkbook.xlsx (Chosen through the file browser)
- Script: Set date and time
Your flow is now ready to be run through Power Automate. You can test it using the Test button in the flow editor or follow the remaining tutorial steps to run the flow from your flow collection.
Run the script through Power Automate
From the main Power Automate page, select My flows.
Select My tutorial flow from the list of flows displayed in the My flows tab. This shows the details of the flow we previously created.
A task pane will appear for running the flow. If you are asked to Sign in to Excel Online, do so by selecting Continue.
Select Run flow. This runs the flow, which runs the related Office Script.
Select Done. You should see the Runs section update accordingly.
Refresh the page to see the results of the Power Automate. If it failed, verify the flow's settings and run it a second time.
Open the workbook to see the updated cells. You should see the current date in cell A1 and the current time in cell B1. Power Automate uses Coordinated Universal Time (UTC), so the time will likely be offset from your current time zone.
Complete the Pass data to scripts in an automatically-run Power Automate flow tutorial. It teaches you how to pass data from a workflow service to your Office Script and run the Power Automate flow when certain events occur.
Submit and view feedback for