How to create a loop in the macro?

How to create a loop in the macro?

A loop is one of the most commonly used functions in automation. It allows recorded actions to be repeated until a specific effect is achieved. It is thanks to the creation of loops that the AUTOMADE tool performs time-consuming human tasks in an instant.

What is a loop and how does it work?

A loop means repeating the data of a given operation indefinitely or until a specific effect occurs.

For example, we can create a loop that checks in Google the air temperature every hour for multiple locations from the dataset, and when this drops below 0, we get an email notification.

How is the loop used in automation?

Almost any repetitive process can be automated precisely thanks to the loop. Activities that take people hours can be reduced to minutes or even seconds with the AUTOMADE tool. Regardless of the industry and department in a company, loops are used in almost every macro. We write more about specific application examples in the article “Which processes can be automated with the AUTOMADE tool?”.

How to create a loop in the macro?

Loop creation in recording mode

The first method of creating a loop is available when recording a macro. After pressing the “Record” button, click on “Tools” and select the “Append Loop” button. Once you name a loop and confirm, each subsequent step you perform will be grouped as one loop if a dataset is recognised during recording.  

 

Loop creation in macro editing mode

 

The second option is to create the loop after the macro has already been recorded. To do this, go to the Advanced view where you can see all the steps and select the ones you want to create a loop from. To select the steps:

 

  • click the first step from which you want to start the loop and then, holding down the SHIFT key, click the last step, or
  • while holding down the CTRL key, left-click each step you want to delete.

 

Once you have selected the steps, right-click on any of them and select “Group steps” and “Loop” from the context menu.

 

 

The tool will create a block with the selected steps. Click the block to open the edit options.

 

In the Number of attempts field, enter how many times the loop is to be repeated, i.e. how many times all the steps in the loop are executed.

 

The Pause step option will cause the application to pause during playback before reaching the loop.

The Skip this step option will cause the application to skip steps from the loop during playback.

 

The Notes segment is for free use by the user.

 

In the Logging segment, you can set instructions for the application on what message to display when a particular loop effect occurs. You can read more about this function in the article “What is the “Login” function in the AUTOMADE tool used for?”

How to create a loop on a set of data?

The AUTOMADE tool allows you to create loops based on specific datasets, such as tables in Excel sheets or HTML tables. In their case, the loop will terminate when the data in the specific dataset is exhausted.

 

Example:

We want a macro created to transfer data from an Excel sheet to individual PDF files. Our task is to record an action on only the first row and create a loop that will perform the same action on each subsequent row. Just like the case below – we want to create a document visible on the right for each person in the list on the left.

 

 

After recording this operation, in the advanced view we will see all the steps we recorded. At this point, the macro will correctly populate one PDF document, and it will look like this on the graph:

 

Only by creating a loop that repeats this action on the entire dataset will the application complete the task.

We click the first step from which we want to start the loop and then, holding down the SHIFT key, we click the last step. Then click the button from the top panel “Repeat on dataset”. The robot will ask you for the datasets to include in the loop. You need to select the appropriate set, which is, for example, the selected sheet in the Excel file.

This will create a loop that will repeat the action from the first row on all the other rows in the Excel sheet.

 

For all subsequent rows, our macro in the graph will look like this:

As you can see, a loop block has been created in the record set that groups all the loop steps together. The AUTOMADE tool has detected that the loop applies to the Excel sheet and will repeat the action until it runs out of names in the list.

Other types of loops in the AUTOMADE tool

We describe more about loop types and how to use them in macros in the article “What are loop types and what are they used for?”.