Read Excel with Power Automate Desktop

by

Power Automate Desktop is a low code/no code RPA (Robotic Process Automation) software use for automate various tasks through the User Interface on computers.

It can be downloaded and use for free.

Create a Desktop Flow

Open Power Automate Desktop and press New flow at the top left of Console.

Console
Press New Flow at the top of left hand side of Console
Build a flow
Name the Flow name as “Launch Read Close Excel”, Press Create

Create Excel file and Data

Open Excel and enter the information as below and save the file to the Desktop.

Example of file path where Excel is saved:

C:\Users\User\Desktop\Excel Automation (Launch, Read, Close).xlsx

If you don’t want to type information yourself, you can download the file here.

Excel data
Information in the Excel file that will be use for this article

Putting Actions in Workspace

In the Action Pane on the left, find the action you want to trigger the robot to perform, such as “Launch Excel” and drag and drop it to the workspace of the flow designer or double-click on that action then the action will appear in the workspace automatically.

Flow designer
Flow Designer
Actions pane and Workspace
Actions Pane and Workspace are components of Flow Designer
Putting actions in Workspace
You can search for Actions in the search bar at the top of the Actions Pane

Launch Excel

There are 2 types of parameters of “Launch Excel”:

  1. with a blank document : opens a new Excel file.
  2. and open the following document : opens the Excel file on our computer.
Launch Excel with a blank document
Type 1 : with a blank document
Launch Excel and open the following document
Type 2 : and open the following document (you will be asked to enter the Document Path as well)

At the Variables produced section of each action will show the variable that automatically create by Power Automate Desktop which is called “Flow variables“.

For the “Launch Excel” action, it will create the flow variable name as ExcelInstance automatically.

Launch Excel
Set up according to this picture, change the File path to where you saved Excel and press Save

Note: You can rename the flow variable by click at the variable and type the new name. However, just keep in mind that you should name it easy to understand.

Read from Excel worksheet

The parameter of “ExcelInstance” will retrieve the data type of ExcelInstance in our flow, and put it in the dropdown, we can easily choose which Excel file to read the values ​​from (in this case there will be only one value because we only have one Excel file open).

The parameter “Retrieve” can be adjusted in 5 ways:

  1. The value of single cell : read the value from only one Excel cell.
  2. Values from a range of cells : read values ​​from multiple Excel cells. (It can be a single cell or multiple cells)
  3. Values from selection : read the value from the selected cell. (It can be a single cell or multiple cells)
  4. All available values from worksheet read values ​​from the available Excel cells of the Excel worksheet.
  5. Values of named cells : read values ​​from the Name Range that created in Excel.
Read from Excel worksheet parameter
Choose a way for reading values ​​in Excel

In the Start column and End column, you can enter the letter that represent the order of the Excel column or enter the number of the Excel column.

In the Start row and End row, you can enter the number of the Excel row.

For the “Read from Excel worksheet” action, an ExcelData variable will be created automatically.

The data type of this variable will be Text value, Numeric value or Datatable, depending on the format we choose in “Retreive” and the values ​​in Excel cell.

Read from Excel worksheet
Set the settings as in this picture and press Save (Wrote fix row as 11 for now).

Write text to file

We will try to take the values ​​that the robot can read and write them in notepad.

Example file path where Notepad is saved:

C:\Users\User\Desktop\StrawHatCrew.txt

In the parameter “If file exists” there are 2 types to choose from:

  1. Overwrite existing content : Overwrite existing content in the file.
  2. Append content : Write new line from the original file.
Write text to file
Set up according to this picture, change File Path to where we want to save Notepad, then press Save.

Close Excel

The parameter “Before Closing Excel” can be adjusted in 3 ways:

  1. Do not save document
  2. Save document
  3. Save document as : save as new Excel file (you will have to choose the extension and location you want to save)
Close Excel parameter
Choose whether to save or not before closing Excel
Close Excel
Set up as follows and save.

Completed Flow

You will get a flow with 4 actions as shown in the picture below. Press Save and then press Run.

Conpleted flow
Completed Flow

Result 1

You will get all the information in Excel from the column header and data with a comma symbol separating the columns.

Result in Notepad with both column header and data
Result in Notepad with both column header and data.

If you look at the Variable Pane on the right and double click on the ExcelData variable, you will see the data that we ordered the robot to read from Excel.

Variable pane
Variable Pane

In this case, we don’t tell the robot that the data has a column header. The robot will name the columns for us as Column1, Column2, Column3, …

Data in ExcelData variable
Data in ExcelData variable
Advanced option of read from Excel worksheet
Set the Advanced value for the action “Read from Excel worksheet”

Press Save and Run again.

Result in Notepad with only data (without column header)
Result in Notepad with only data (without column header)

If the data in Excel increases/decreases, how do we tell the robot to read it?

Use the action to find the first free row and then subtract 1 to tell Excel’s range.

Find FirstFreeRow
Find FirstFreeRow subtract by 1 to find the data of Excel range

Get first free column/row from Excel worksheet

Drag the action “Get first free column/row from Excel worksheet” before “Read from Excel worksheet”.

You will get Variables produced as FirstFreeColumn and FirstFreeRow. Press Save.

Get first free column/row from Excel worksheet
The value will be collect as a number stored in a variable FirstFreeColumn and FirstFreeRow.

Then double click on the action “Read from Excel worksheet” at the parameter “End row”, select the variable FirstFreeRow and write Expression minus 1.

From Excel above, FirstFreeRow has a value of 12. If we write it in Expression, the program calculates the value as 12 – 1 = 11.

When the data in the Excel file changes, increasing/decreasing It will find the value of the data more flexibly than entering numbers directly.

Expression for find Excel range by using FirstFreeRow variable subtract by 1
Writing Expressions in Power Automate Desktop

Edited Flow

Edited flow
Edited Flow

Try adding data in Excel and then Run.

Add data in Excel
Add 1 line of information

Result 2

Result in Notepad with only data and add 1 line of data
Result in Notepad with only data (no column header) and adding 1 line of data.

Thank you for the mock data from One Piece Wiki.

For anyone who wants to see the Power Automate Desktop code in this article, you can copy the code on github and paste it into the Workspace of Power Automate Desktop, but you’ll have to make some adjustments by yourself. (Try reading and reviewing this article again. You can definitely do it. ❤)

Power Automate Desktop code in github
Click on the first line of code, press Ctrl+A, Ctrl+C, and then paste it into the Workspace Power Automate Desktop.

Hope this article will be useful to the people who just starting to study Power Automate Desktop, if you have any questions about this article, you can comment and ask section below.

Don’t forget to press like, share, subscribe for good articles from now on (press the subscribe button and you will receive a mail confirming your subscription to confirm again as well).

Until we meet again, Happy Automating!! 😁

Did You Enjoy this Article?

Subscription to get new articles sent to your inbox each week for FREE

Question?

If you have any questions or feedback about this article please leave a message in the comments section below.


Comments

Leave a comment

Subscribe to get new articles sent to your inbox each week for FREE