You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorials/excel-power-automate-trigger.md
+22-22Lines changed: 22 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,16 @@
1
1
---
2
2
title: 'Tutorial: Automatically save content from emails in a workbook'
3
3
description: A tutorial about running Office Scripts for Excel through Power Automate when mail is received and passing flow data to the script.
4
-
ms.date: 11/29/2023
4
+
ms.date: 11/14/2025
5
5
ms.localizationpriority: high
6
6
---
7
7
8
8
# Tutorial: Automatically save content from emails in a workbook
9
9
10
-
This tutorial teaches you how to use an Office Script for Excel with an automated [Power Automate](https://make.powerautomate.com) workflow. Your script will automatically run each time you receive an email, recording information from the email in an Excel workbook. Being able to pass data from other applications into an Office Script gives you a great deal of flexibility and freedom in your automated processes.
10
+
This tutorial teaches you how to use an Office Script for Excel with an automated [Power Automate](https://make.powerautomate.com) workflow. Your script automatically runs each time you receive an email, recording information from the email in an Excel workbook. Being able to pass data from other applications into an Office Script gives you a great deal of flexibility and freedom in your automated processes.
11
11
12
12
> [!TIP]
13
-
> If you're new to Office Scripts, we recommend starting with [Tutorial: Create and format an Excel table](excel-tutorial.md). If you're new to Power Automate, we recommend starting with [Tutorial: Update a spreadsheet from a Power Automate flow](excel-power-automate-manual.md). [Office Scripts use TypeScript](../overview/code-editor-environment.md) and this tutorial is intended for people with beginner to intermediate-level knowledge of JavaScript or TypeScript. If you're new to JavaScript, we recommend starting with the [Mozilla JavaScript tutorial](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Introduction).
13
+
> If you're new to Office Scripts, start with [Tutorial: Create and format an Excel table](excel-tutorial.md). If you're new to Power Automate, start with [Tutorial: Update a spreadsheet from a Power Automate flow](excel-power-automate-manual.md). [Office Scripts use TypeScript](../overview/code-editor-environment.md) and this tutorial is intended for people with beginner to intermediate-level knowledge of JavaScript or TypeScript. If you're new to JavaScript, start with the [Mozilla JavaScript tutorial](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Introduction).
14
14
15
15
## Prerequisites
16
16
@@ -24,7 +24,7 @@ Power Automate shouldn't use [relative references](../testing/power-automate-tro
24
24
25
25
1. Go to the **Automate** tab and select **New Script**.
26
26
27
-
1. Replace the existing code with the following script and select **Run**. This will setup the workbook with consistent worksheet, table, and PivotTable names.
27
+
1. Replace the existing code with the following script and select **Run**. This step sets up the workbook with consistent worksheet, table, and PivotTable names.
28
28
29
29
```TypeScript
30
30
function main(workbook:ExcelScript.Workbook) {
@@ -51,11 +51,11 @@ Power Automate shouldn't use [relative references](../testing/power-automate-tro
51
51
52
52
## CreateanOfficeScript
53
53
54
-
Createascriptthatlogsinformationfromanemail. You'll want to track which days of the week you receive the most mail and how many unique senders are sending that mail. Your workbook has a table with **Date**, **Day of the week**, **Email address**, and **Subject** columns. Your worksheet also has a PivotTable that is pivoting on the **Day of the week** and **Email address** (those are the row hierarchies). The count of unique **Subjects** is the aggregated information being displayed (the data hierarchy). The script will refresh that PivotTable after it updates the email table.
1.Theflowthatyou'll create later in the tutorial sends the script information about each email that'sreceived. Thescriptneedstoacceptthatinputthroughparametersinthe`main`function. Replace the default script with the following script.
58
+
1.Theflowthatyoucreatelaterinthetutorialsendsthescriptinformationabouteachemailthat's received. The script needs to accept that input through parameters in the `main` function. Replace the default script with the following script.
59
59
60
60
```TypeScript
61
61
function main(
@@ -79,23 +79,23 @@ Create a script that logs information from an email. You'll want to track which
79
79
let pivotTable = pivotTableWorksheet.getPivotTable("Pivot");
80
80
```
81
81
82
-
1.The`dateReceived`parameterisoftype`string`. Convertthattoa [`Date`object](../develop/javascript-objects.md#date) soyoucaneasilygetthedayoftheweek. Afterdoingthat, you'll need to map the day'snumbervaluetoamorereadableversion. Addthefollowingcodetotheendofyourscript, beforetheclosing`}`.
82
+
1.The`dateReceived`parameterisoftype`string`. Convertthattoa [`Date`object](../develop/javascript-objects.md#date) soyoucaneasilygetthedayoftheweek. Afterdoingthat, youneedtomaptheday's number value to a more readable version. Add the following code to the end of your script, before the closing `}`.
83
83
84
84
```TypeScript
85
85
// Parse the received date string to determine the day of the week.
86
86
let emailDate = new Date(dateReceived);
87
87
let dayName = emailDate.toLocaleDateString("en-US", { weekday: 'long' });
:::imagetype="content"source="../images/power-automate-params-tutorial-1.png"alt-text="The Automated flow option in Power Automate.":::
157
157
158
-
1.Inthedialogwindowthatappears, enteranameforyourflowinthe**Flowname**textbox. Under**Chooseyourflow's trigger**, select **When a new email arrives** from the list of options. You may need to search for the option using the search box. Finally, select **Create**.
158
+
1.Inthedialogwindowthatappears, enteranameforyourflowinthe**Flowname**textbox. Under**Chooseyourflow's trigger**, select **When a new email arrives** from the list of options. You might need to search for the option by using the search box. Finally, select **Create**.
159
159
160
160
:::imagetype="content"source="../images/power-automate-params-tutorial-2.png"alt-text="Part of the Power Automate flow showing the 'flow name' and the 'choose your flow's trigger' options. The flow name is 'Record Email Flow' and the trigger is the 'When a new email arrives in Outlook' option.":::
1.Inthe**Addanaction**taskpane, searchfor"Excel run script". Choosethe**ExcelOnline (Business)**connector's **Run script** action. This action runs a script from your OneDrive on a workbook. If you want to use a script stored in your team'sSharePointlibrary, youshouldusethe**RunscriptfromaSharePointlibrary**action.
167
+
1.Inthe**Addanaction**taskpane, searchfor"Excel run script". Choosethe**ExcelOnline (Business)**connector's **Run script** action. This action runs a script from your OneDrive on a workbook. If you want to use a script stored in your team'sSharePointlibrary, usethe**RunscriptfromaSharePointlibrary**action.
168
168
169
169
:::imagetype="content"source="../images/power-automate-tutorial-4.png"alt-text="The action selection task pane showing actions for the Excel Online (Business) connector. The Run script action is highlighted.":::
1.Next, you'll select the workbook and script to use in the flow step. For the tutorial, you'llusetheworkbookyoucreatedinyourOneDrive, butyoucoulduseanyworkbookinaOneDriveorSharePointsite. Specifythefollowingparametersforthe**Runscript**action:
:::imagetype="content"source="../images/power-automate-params-tutorial-3.png"alt-text="The Power Automate run script action showing the options that appear once the script is selected.":::
186
186
187
187
1.Select**Save**.
188
188
189
189
:::imagetype="content"source="../images/power-automate-tutorial-6.png"alt-text="The Save button in Power Automate.":::
Whentheflowistriggeredandsuccessfullyrunsyourscript, youshouldseetheworkbook's table and PivotTable update.
201
+
Whentheflowtriggersandsuccessfullyrunsyourscript, youseetheworkbook's table and PivotTable update.
202
202
203
203
:::imagetype="content"source="../images/power-automate-params-tutorial-4.png"alt-text="A worksheet showing the email table after the flow has run three times.":::
204
204
205
205
:::imagetype="content"source="../images/power-automate-params-tutorial-5.png"alt-text="A worksheet showing the PivotTable after the flow has run three times.":::
0 commit comments