Sie sind auf Seite 1von 106

RPA School

(VBA + Blue Prism)


V1.0

PCS Argentina
Welcome
This course is aimed at people with no
programming background.

Once you complete this course you should


be able to understand programming code
and start developing your own solutions in
Visual Basic for Applications (VBA) and
Blue Prism (BP).
Schedule

Day 1 Day 2, 3, 4 Day 5


• Introduction to VBA • Introduction to Blue • Evaluation &
Prism Workshop
• Interface, Macros &
Variables • Installing Software

• Control Flow • Useful Commands

• Modularization • Practice & Exercises

• Oriented Objects Program • Programming with Blue


(OOP) Prism

• Excel Cases • Q&A.


Introduction
What does programming mean?
Programming makes it possible to create
computer software, apps and websites
by writing instructions understandable
by a computer.

What is VBA?
Visual Basic is a programming language
developed by Microsoft, VBA refers to a
variant aimed at working with Office and
a few other compatible apps.
VBA User Interface

Before you Begin

VBA Interface Overview


Screencast Notes
• Before you begin - Setting up developer tools
– Enable the developer tab: File > Options > Customize Ribbon
– Configure VBA
• Tools > Options > Editor > Require Variable Declarations
• Tools > Options > General > Configure error handling to break in class module
• VBA Interface Overview
• Project Explorer: Shows open files and their components
– Workbooks & Sheets
– Modules
• The Editor: Write code inside a file component.
• The Immediate window: Used for debugging.
Macros

Recording a Macro Macro Code Analysis

Executing a Macro Code Debugging


Introduction

What is a Macro?
A macro is a sequence of user actions
that can be recorded by Office and can
be repeated automatically at any time.

When you record a macro, Excel will


translate your actions into code.
Screencast
• Recording a Macro: Developer > Record Macro
• Executing a Macro
– From the Macro List: Developer > Macros
– From a shortcut
• Macro Code Analysis:
– Sub Procedures
– Instructions
– Comments
• Code Debugging
– Playing, Pausing or Stopping macro execution from the IDE
– Executing a macro line by line: F8
– The instruction pointer
– Breakpoints
Practice

C) Debug you Code


B) Filter Out Employees
Execute your code line by
A) Write Hello World Record a Macro that filters line with F8 and add some
Record a macro that writes and deletes employees with
an employee level that is less comments explaining what
“Hello World” in cell A1. different lines do.
than 10.

Execute your macro from Execute the macro from the Add some breakpoints and
the Macro List and from a VBA editor (using the play execute your macro fully.
shortcut. button or F5).
Variables & Constants

Variable Types Assigning Values Declaring Constants

Declaring Variables Working with Variables Best Practices


Introduction
What is a variable?
A Variable is a location in the computer
memory used to store a value. A
Dim year as Integer ‘ Declaration variable has a name that should describe
what it contains and is used to access or
year = 1980 ‘ Assigning a value modify it’s value.

Debug.Print year ‘ Prints 1980 What is a constant?


Like Variables, Constants are also used
to store information, however a
Constant initial value can’t be modified.
Variable Types
Variables of different types are used to store different kind of data.

Type Description Examples


Integer Holds integer numbers. 1, 2, 3
String Holds text values. “Johnn”, “Paul”, “George”
Double Holds numbers with decimals. 0.1, 1, -1.0, 1
Boolean Can be either True or False True, False

Other types of variables include: Long, Date, Currency, Decimal, Single, Variant and
Object (this will be very important later on).
Screencast
• Declaring variables: DIM [variable name] AS [datatype]
• Assigning values
• Working with Variables
– Debug a variable value
• Mouseover
• In the Immediate window (Debug.Print, the interrogation mark)
• Declaring constants: CONST [constant name] AS [datatype] = [value]
• Best Practices
Best Practices

Name Variables Appropiately Always use Local Variables Keep “option explicit” in all
Choose descriptive names for AlwaVariables stored outside modules
procedures and variables like procedures are called Global Having Option Explicit at the
“age” instead of “var1”, Variables and using them is top of each module makes it
employ a naming convention considered a bad practice. mandatory to specify variable
and tabulate your code. types. Saving future
headaches.

You can find Microsoft’s recommendations for naming variables here


Practice

C) Calculate person’s age


B) Get the average Create a procedure that
A) Show Full Name
Write a procedure with takes the year a person has
Create a procedure with
two variables of type been born and the current
variables containing a
person’s name and Double. year and prints his current
surname. age to the screen.
The procedure should
The procedure should print calculate and print their
the full name of the person average value.
to the screen.
It’s time for a break
Control Flow

Conditions Loops

Operators
Introduction
What does control flow mean?
Sometimes we don’t want our program
to execute instructions sequentially.
Instead, we might need it to do one
thing or another depending on a
condition. Or we might need it to do
something multiple times before
continuing.

Changing the order a program follows to


execute instructions is called Control
Flow.
Conditions

Dim hunger as Integer


hunger = 5

Conditional expressions make a


If hunger > 2 Then program perform different instructions
Debug.Print “Feed” ‘ Executed if True depending on whether a certain
Else
condition is true or false.
Debug.Print “Play” ‘ Executed if False
End If
Operators

Type Description Examples


= and <> Checks if two values match 1 = 2, 1 <> 2
> and < Checks if A is bigger than B 2 > 1, 1 < 2
>= and <= Checks if A is bigger or equal than B 2 >= 1
And Both conditions must be true 1 = 2 And 2 > 1
Or One condition must be true 1 = 2 Or 2 > 1
Not Negates the statement Not 1 = 1
Screencast
• Conditions
– Linear execution vs If Statements: See how the flow of execution is changes using F8
– If statements
• Simple If Statement
– Use the different operators to create a condition
• Else and ElseIf
• Nested Ifs
– Select Case Statement: Compare a variable for equality against different values.
Practice

B) Can a person drive?


C)C) Complete the month
Write a procedure with
…Write a procedure with a
A) Check Lottery Number two variables, containing a variable containing a month
Write a procedure that person’s age and whether in short-form (Jan, Sep…).
evaluates a variable with a he has a driver’s licence
lottery ticket number and (True or False). Use a Select Case statement
to turn the variable value
prints to the screen “YOU
into a full month (E.g.: Jan >
WIN” if the number is 10 Evaluate both variables and January, Sep > September).
or 20. print “OK” if the person can
drive.
Loops

Dim counter as Integer

A loop is a sequence of instructions that


For counter = 1 To 10
is repeated multiple times.
Debug.Print “Tick”
Next counter
Types of Loops

For While
Description The for loop is run for a fixed number of The while loop is run until a certain condition is
times. met.
When to use it You know the number of iterations you They are best suited when you don’t know
need to do before entering the loop. ahead of time the number of iterations that
you need to do.
Example Dim Counter as Long Do While GamePaused = False

For Counter = 1 To 10
Loop
Next Counter
Screencast
• Loops – Compare using F8
– Do While Loop
• Repeat instructions while the condition is true
• Evaluation can be at beginning or end
– Do Until Loop
• Repeat instructions until the condition becomes true
• Evaluation can be at beginning or end
– For Loop
• Repeat an instruction a fixed number of times
– Best Practices
Best Practices

Prevent infinite loops Only use loops if necessary


Make sure the condition for Modern computers are very
the loop to end will be fast, however loops with a lot
reached eventually or your of iterations can make a
program will crash. program go slow. Before using
a loop make sure you have
exhausted all other options.
Practice
C) Videogame
Write a procedure with a
variable
The Dashholding your
Project
B) 2 Multiplication Table
character lives.
Write a procedure with a
A) Print Numbers Until 80 variable holding an integer.
Write a procedure that Write a loop that keeps
prints to the screen all the substracting lives while
The procedure should
integers between 1 and 80 they are bigger than 0.
write the multiplication
using a For loop. When lives reach 0 Print
table for that variable.
Game Over.
Modularization

Sub-Procedures Functions Modules

Parameters VBA Functions Best Practices


Introduction

What is modularization?
Dividing a program into smaller parts of
code where each piece handles a
specific task is known as modularization.

Using Procedures is a way to modularize


our code. A procedure is a section of a
program that contains a series of
instructions to perform a specific task
Sub-Procedures

Sub ShowAlert()
Debug.Print “Alert!" What are sub-procedures?
End Sub The basic procedures in VBA are called
Subs and are enclosed by a Sub and End
Sub statement.
Sub ProceduresSample()
ShowAlert ‘ Execute procedure
Once a Sub is defined it can be called
End Sub anywhere on your code.
Parameters

Sub ShowCustomAlert(message as String)


Debug.Print “Warning: “ & message
Parameters make it possible to transfer
End Sub
values and variables from a procedure to
another.
Sub ParemetersSample()
ShowCustomAlert “Error 123"
End Sub
Screencast
• Sub-Procedures (examples in previous slide)
– Creating a procedure
– Calling a procedure
• 2 ways: With or without the call keyword
• Parameters
Practice

C) Any Multiplication table


B) Which is bigger? Write a procedure that
A) Greet a Person receives a number and prints
Write a procedure that
Write a procedure that it’s full multiplication table.
informs which is the E.g.:
receives a name as biggest one of three 2
parameter and greets this numbers. 4
person with his name.
6
8…
Create a second procedure
that calls this subroutine.
Functions

Function Power(Number As Double) As Double


What are functions?
Power = Number * Number
End Function
Functions are another type of
procedures which are enclosed by
a Function and End Function statement.
Sub Example()
Debug.Print Power(2) ‘The value returned by
the function is assigned to a variable The difference a between a Sub and
End Sub a Function is that functions can return a
value to the calling procedure.
Screencast Notes
• Functions
– Creating a function
– Calling a function and getting it’s return value
• VBA Pre-defined functions
• Msgbox
• Len
• Trim
• Left
• Right
• Round
• Modules
– Used to store code more safely than sheets
– Private and Public procedure
• Best Practices
Practice

C) Calculator
B) Which Is Longest Create a function that receives
A) Is it positive? Create a function that receives two numbers and a string with
Write a function that an operator such as “+”, “-”,
two strings and returns the
“*”, “/”. The function should do
receives a number, and longest one. the operation between the two
returns true if it’s positive numbers and return the result.
or false if it’s not. Tip: Use the pre defined
function LEN() Use this function in a
Use this function in a procedure and print it’s result.
procedure and print it’s
result.
Best Practices

Name Procedures Keep it Simple Place Code in Modules


Appropriately Develop short, single purpose While it’s possible to write
Use descriptive names for procedures. As a rule of code inside sheets, sheets can
your procedures and always thumb, if a procedure is more be deleted, copied or moved.
indent instructions inside than a page long you should Moreover modules can be
them. divide it in smaller ones. exported and imported into
another projects.
It’s time for a break
Object Oriented Programming

Properties & Methods Excel Object Model Overview Best Practices

VBA Notation Working with objects


Introduction
0,90m
What is Object Oriented
Programming?
Object Oriented Programming is a type
of programming which uses “Classes”
and “Objects” to organize programming
2,00m code.

A Class is a template to create Objects, it


provides a definition of what properties
(e.g.: height and color) and methods an
object can have (how it can be
manipulated, e.g.: Open, close).
Properties & Methods
Color

Open
Knob

Close Door Material

Object
Knock
Color Property

Our door object model Method


VBA Notation
Range
Open
Use a dot to go deeper in an object’s
Worksheets hierarchy. E.g: ThisWorkbook.Save

Use parentheses to specify an


Close Workbook object in a collection. E.g:
Name
ThisWorkbook.Worksheets(1).Name

Save
Name

Workbook Object Model at a glance


Screencast
• VBA Notation
– Properties (Similar to variables)
• Collections: Two ways to reference ítems.
– Methods (Procedures and Functions belonging to the object)
• Excel Object Model Overview
• Working with objects
– Ways to find properties and methods (IntelliSense, Object Browser, Macro Recorder)
– For each loop
– Assigning an object to a variable or argument
– With statement
• Best Practices
Excel Object Model Overview
• Application
Application – Properties: ScreenUpdating, Calculation, EnableEvents
– Methods: Calculate, Quit
• Workbooks
Workbooks – Properties: Name, Path, Saved, Worksheets
– Methods: Save, SaveAs, Open, Close, Add, Count
• Worksheets
Worksheets – Properties: Name, Visible, Range , Cells, Columns, Rows
– Methods: Add, Delete, Count , Protect, Unprotect
• Range/Cells
Range – Properties: Value, Formula, Count, Address
– Methods: Copy, Cut, PasteSpecial, Offset
Best Practices

Always use full references Simplify your code using With


Reference the full Always use the with statement
Workbook.Sheets().Range() when refering to the same
whenever possible to prevent object or property in multiple
errors during processing. instructions.
Practice

C) Import Workbook Data


B) Show Workbook Info Modify the previous program,
A) Change Cell Value Before starting: Point the file so that it completes the greyed
Write a program that writes path in the Module5 sheet out cells in the Module5 sheet
”Hello World”, to the range A1, to an Excel file in your
computer. and copies the first three
of the first sheet of the original columns of the opened file into
workbook. a new sheet of the original
Write a program that opens
the file, and uses a msgbox to Workbook.
Then it should print to the show it’s name and number
screen the value of A1 to verify of sheets. Afterwards it
it’s correct. should close the file.

Remember you can set Application.ScreenUpdating to False before your code for better performance.
It’s time for a break
VBA User Interfaces

Basic UI Elements Working with Forms

Working with Controls


Introduction

What is a User Interface?


A user interface is everything that allows
a person to interact with a computer.
This includes both the software and the
hardware.
Basic UI Elements

Combo box Button Text Box

Check Box Option Button

List Box

Toggle Button
Working with Controls

What is a Control in VBA?


Controls are basic elements, such as
buttons, text fields and drop-down lists,
that can be placed on an Excel
Worksheet to allow users interact with
your program.
Screencast
• Working with controls
– Creating a control
• Form Controls vs ActiveX
• ActiveX Control properties
– Interacting with controls
• Running our code on user click/interaction
– ActiveX: View Code
• Retrieving values from form fields
– ActiveX: For every ActiveX control an object will be made available
Practice

C) Add a Sheet
B) Say Hello by Name Add radio buttons with 3
A) Say Hello Add a Text Box Control to different greetings like:
Create a procedure that uses write a name and modify Hello, Bye, Good Morning
the pre-defined function the previous program so and modify the previous
MsgBox to say Hello. that it greets you based on program so that it greets
whatever name you typed. you based on your choice
Create a button that executes of greeting and input
your sub. name.
It should not greet you if
your name is Alice.
It’s time for a break
Working with Forms

What is a Form?
Forms are a yet another way to allow
users interact with your program.

Forms don’t have to be placed on a


sheet but can be displayed on individual
Windows, making them more
convenient than controls when many
inputs are required.
Screencast
• Working With Forms
– Creating a form: Right click in Project Explorer > Insert > UserForm
– Form Methods
• .Open Opening a form: Assign a procedure with [FormName].Show to a control
• .Close Closing a form: Me.Hide
– Interacting with a form
• Running code on user click/interaction (Double click form element to generate sub)
• Retrieving values from form fields: Same as ActiveX
– Retrieving values from msgbox
• Completing a ComboBox (.Add Method)
Practice

C) Register To Training
B) Training Create a form with an input
A) Show a Form Create a form with an input to write for an email address, and
your name and a checkbox saying “I three trainings to choose
Create a new form and add it a accept the terms and conditions”.
Quit button that closes it. froom.
Add an Ok button. On click if you
Create an ActiveX control that accepted the terms and conditions it When the ok button is
opens the form. should show your name else it clicked add the submitted
should show the message “Please
accept the terms and conditions” data to the end of the
Experiment with different (use the function msgbox). atendees list.
properties and methods of
User Forms and User Form
Controls.
Common Excel Case Scenarios

For Each Loop Reusing Classes

Saving Macros to the Interfacing with other Apps


Ribbon
Screencast
• For Each Loop
– Making All Sheets Visible
• Adding Macros to the Ribbon
– How to show the personal Workbook
– Selection, ActiveCell and ActiveSheet
• Interfacing with other apps easily by Adding External Resources (like Outlook)
– Importing Classes
– Referencing Object Libraries: Tools > References
Practice

C) Confirmation Email
B) Make All Cells Visible Import the class Outlook
Create a macro that makes Utils and create a macro that
all cells in the ActiveSheet iterates through the list of
visible. atendees from module 6 and
creates an email draft for
each one with the text: “You
Save this Macro to a have been registered
module in your personal successfuly to the training
Workbook and add it to [Training name]”.
your ribbon bar.
Q&A
Use this time to ask any questions or request
any topics you want explained.
Keep Learning
There are a lot of great resources to help you.

Stackoverflow.com Google.com Automation Team


Stack Overflow is a Q&A Remember to add the VBA We are the go to team for
website for professional and keyword on your search creating automated
enthusiast programmers. query. solutions to save time and
costs. Feel free to contact us
with any questions!
For any automation questions
don’t hesitate to reach us:

Thank you for coming nicolas.e.tezari@accenture.com


Introduction to Blue Prism
Introduction to Blue Prism
Robotic Automation refers to process automations where computer software drives existing enterprise
application software in the same way that a user does. This means that unlike traditional application
software, Robotic Automation is a tool or platform that operates and orchestrates other application
software through the existing application's user interface and in this sense is not "integrated".

Blue Prism's Robotic Automation software enables business operations to be agile and cost effective
through rapid automation of manual, rules based, back office administrative processes, reducing cost
and improving accuracy by creating a "virtual workforce".

The virtual workforce is built by the operational teams or accredited Blue Prism partners using our
robotic automation technology to rapidly build and deploy automations through leveraging the
presentation layer of existing enterprise applications. The automations are configured and managed
within an IT governed framework and operating model which has been iteratively developed through
numerous large scale and complex deployments
Introduction to Blue Prism
Install Software
Become familiar with Blue Prism

• Process Studio
• Interfaces & Main Commands
• Sample Exercises
Become familiar with Blue Prism
Process Studio
Become familiar with Blue Prism
Become familiar with Blue Prism
Become familiar with Blue Prism
Interface & Main Commands
Become familiar with Blue Prism
Become familiar with Blue Prism
Become familiar with Blue Prism
Become familiar with Blue Prism
Example Exercise
Practice and Exercises

• ….
Exercise (1)
Excel: Getting Values (from a DataRange)

• ….
Exercise (2)
Excel: Getting Values (from a DataRange)

Make a process that opens an excel file, get the value of


each cell (on column A), and finish when has reached the last
cell with value.

BluePrism Tips:
 Create an Excel Instance.
 Make visible the Excel instance. (Show)

 Open the file: “ciudades.xlsx”. (Open Workbook)

 Select the ‘Ciudades’ sheet, and set the focus in the “A1” cell. (Activ. Worksheet – Got to cell)

 Scroll through all the ‘Column A’ cells, assigning each value into a BP Data.
 Finish the robot process when has reached the las cell of the data range ( Go to next cell -

Decision: (if cell is empty) - When is empty -> END.


Exercise (2)
Collections

• ….
Exercise (2)
Collections

Make a process that opens an Excel file with a list of


provinces, stores the list in a collection and searches the
provinces in a search engine, one by one.

BluePrism Tips:
 Be sure to specify the correct file path for the Excel file.
 Give the browser approppriate time to show the search results on the screen.
Exercise (3)
Identifying Objects

• ….
Exercise (3)
Identifying Objects

Make a process that searchs a text in a Browser page, for


example: “What to do in Buenos Aires”, then when the results
has been shown, search another text again, for example:
“What to do in Amsterdam”.
BluePrism Tips:
 Ensure / Validate if the Browser is opened, otherwise you must launch it.
 Ensure to put some ‘Waits’ propertly (in each step you consider), to avoid getting unwanted
errors.
 Use descriptive names in each step or those data prism command you use, to facilitate the
reading flow process.
Sample Exercise: Browser
Setting application with “Application Modeler”
Sample Exercise: Browser
Identyfing Objects
Sample Exercise: Browser
Identyfing Objects
Once identified your object, when you
press the “Highlight” button, you will
see highlighted the object in the
application, ensuring you have done
correctly.
Sample Exercise: Browser
Identyfing Objects
Do the same for identify
the “press button search”.
Sample Exercise: Browser
Use your identified objects
User your identificated
objects in the commands as
well as you need…
Sample Exercise: Browser
Making Your Robot

Finally, you’re
able to start
building your
robotics
design.
Exercise (4)
Exceptions

• ….
Sample Exercise: Exceptions
Forcing an Error
We have a division example.
A value is divided by a divisor
number.
Then, a calc sustract 1 (one) unit
to the divisor number 1, and put
the whole operation in a loop.
In some time, the divisor number
will be 0 (zero) and the process
will show an error.
Sample Exercise: Exceptions
Forcing an Error
The errors appears clearly…
Sample Exercise: Exceptions
Adding the Exception and a recovery stage

We have added an “Exception” that


inmediatly will start when the error
happens.
After the error is submited, the
process will resume (continue) from
the “Recover” command.
Always you use an exception, you
shall use a Recovery command.

In this way, the process will not be


stopped before an error, and the
robot will may continue its course.
Sample Exercise: Exceptions
Adding some useful information to our process

If you prefer, you can store the


“Exception Detail” in a “data item“
for use it later at your own
convenience in the robotic process.

For last, note that we put the


operation and the exception inside
the same block, named “Stage2”.
This is useful for group each
exception with its own error and
avoiding conflicts with anothers
exceptions that could be in the same
process.
Reply This Exercise…

1) Make a división between two numbers, and put this operation in a


loop cycle. Sustract 1 (one) unit to the divisor number in each cycle.

2) When the error happens, try to add an exception to avoid the


process crahses, and resume it to the end.

3) Put some description of the error in a BP Data item.


Exercise (5)
Cycles and Loops

• ….
Sample Exercise: Cycles and Loops
Controlling repetitive processes

In this case, we are repeating a


process five (5) times.

There is a variable (called “Variable”)


that controls the cycle.
Note that we are combining a
decision with a mathematical
calculation. In this case, when the
variable value is greater than 5, the
program exits the loop and goes to
the End.
Exercise (5)
Cycles and Loops

Make a process that goes through a table conformed by


columns and rows.
There are 5 rows and 4 columns in the table.
The process must be able to pass through all cells, which are
identified by row and column number.

BluePrism Tips:
 Use one Data Set for the row number and another for the column number.
 Make sure the variables do not exceed the máximum row and column numbers.
Exercise (6)
Decision

• ….
Simple Decision

In the left image, we can see a


simple decisión process. The
program assigns a value to a variable
and then compares the value to a
reference value. The result is either
YES or NO.

See how the condition is defined: in


the Decision Properties dialog box.
In this case, the reference value is
TIP: You may use
logical operators
10, and the condition is that the
such as AND, OR variable is greater than 10:
and NOT. Var > 10 -> TRUE (Yes)
Var <= 10 -> FALSE (No)
Multiple Decision

If the condition can have multiple


oucomes, rather tan YES or NO,
we have to use a CHOICE.

See in the insert box


above how the conditions
are defined.
The program takes a different route
depending on the value of the
variable.

Otherwise: If none of the conditions


are TRUE.
Exercise (6)
Decision

Make a process that assigns the cost of a bottle of a


beverage according to the place of purchase.

BluePrism Tips:
 Use two or more places.
 Be sure to take into account the possibility of the person choosing a non-listed retailer.
 Choice of beverages and/or retailers is personal. May be whichever, provided that the
exercise can be done.
Final Exercises
Using the Excel file called “Listado Provincias”:

• For each province in the list, look up the population in Google, writing
“[province name] población”.
• Store the population in the Excel file, column B, right of the name.
• For the most and least populated provinces: search for activities to be
done in it.
• Sort the list in descending order.

OPTIONAL EXERCISE:
• Develope a robot for a process of your choice.
Thanks for coming
Have a nice day!

Das könnte Ihnen auch gefallen