Update a SpreadSheet from a Power Automate Flow

Office Scripts in Excel lets you automate your day-to-day tasks. Use the Action Recorder to turn manual steps into reusable scripts. Edit those scripts or create new ones with the Code Editor. We will learn how to record actions and prepare an office script, and then we will learn how to automatically run that script from Power Automate.

Step 1. Open Excel and in the Automate tab, click on the "Record Actions" tab.

Record Actions

you see the right side panel after starting recording as shown in the below image.

Panel

Step 2. Now, you can add any type of data to the sheet and do any formatting in the sheet. After adding all the data and after all the formatting you can stop the recorder from the right side panel. After that go to the code editor and the recorded actions are saved as a script.

Recorded actions

Step 3. Now open Power Automate with https://make.powerautomate.com/ and create a new cloud flow triggered manually.

Power Automate

Step 4. Add the new action to run the script automatically.

New action

Step 5. Add parameter values as shown in the screenshot below. Here is the Excel saved on the OneDrive.

OneDrive

Step 6. Click on the Save button and save the flow.

Step 7. Open the worksheet and remove all the data from it. Add the following code in the code editor of the script.

// Get the cells at F1 and G1.
let dateRange = selectedSheet.getRange("F1");
let timeRange = selectedSheet.getRange("G1");

// Get the current date and time using the JavaScript Date object.
let date = new Date(Date.now());

// Add the date string to F1.
dateRange.setValue(date.toLocaleDateString());

// Add the time string to G1.
timeRange.setValue(date.toLocaleTimeString());

Code Editor

Step 8. Go to Power Automate and Click on the Run button to run the flow. All the data will be filled in the worksheet.


Similar Articles