A repository of notes about Performance Testing, Automation, RPA, and Web Design.

  • UiPath

    Show all posts related to UiPath

  • Windows

    Show all posts related to Windows

  • Web Design

    Show all posts related to Web Design

[UIPath] VBA macro for formatting headers in Excel

Here's a neat piece of code I use whenever I needed to apply a macro that formats headers on an Excel workbook. I always come across this step whenever I write a datatable to an Excel file. Datatables are being copied as plain text so you have to format it to make it look more presentable. The goal is to programmatically turn this unformatted workbook...


to a formatted one which is very much readable and ready for reporting:


Here you go:

Private Sub FormatHeaders()
    Dim ws as Worksheet
    For Each ws in Worksheets
        ws.Activate
        Cells.EntireColumn.Autofit
        Cells.EntireRow.Autofit
        Rows("1:1").Font.Bold = True
        Range(Range("A1"),Range("A1").End(xlToRight)).Interior.Color = RGB(173, 216, 230)
    Next
    Sheets(1).Select
End Sub

What this macro does is loop through all the sheets in the workbook and do the following:
  • Autofit all columns
  • Autofit all rows
  • Bold the headers
  • Add background color to the headers
Then it will focus back on the first sheet.

Now it's easy to read and ready to sent out. Remember to setup MS Excel's trust settings if you're going to run an external macro.

Hope this helps!
Share:

[UIPath] Error: Could not connect to UiPath Robot Service. Make sure the service is started!

I'm encountering this error a lot these days, I'm not sure why. But for some reason this error only appears when I'm running a workflow that was created using an older version of UiPath. When I try to run the workflow on Studio, it gives me this message:


As suggested by the prompt, I made sure that the UIRobot service is started. But it still doesn't work. Restarting the service doesn't work either unless it's done in the following order (see below). So here's how I got through this error:


1. Close UiPath Studio
2. Run services.msc (win + R >> services.msc)
3. Look for UiPath Robot service
4. Stop UiPath Robot service (right click >> stop or look for the stop button on the toolbar)
5. Open UiPath Studio and load the workflow you want to run
6. Start UiPath Robot service (right click >> start of look for the start button on the toolbar)
7. Run the workflow on UiPath Studio

That should do it! Hopefully it works for you too :)
Share:

[UIPath] How to schedule robotic workflows without Orchestrator

Note: Task Scheduler execution is no longer supported since version 2017.1 
(source: https://forum.uipath.com/t/unattended-robots-w-or-w-out-orchestrator/18534/5)

An alternative to UIPath Orchestrator that we've found effective in scheduling robotic processes is Windows built-in Task Scheduler. We got the idea after learning that workflows can be run from the command line.


The concept is simple, first you create a script that starts a robotic process using UIPath robot. Then, you create a new task on Task Scheduler, load that batch file as an Action, and set your desired schedule.

Here's how:
Creating the script file

Open notepad and type the following command:

"C:\Program Files (x86)\UiPath\Studio\UIRobot.exe" 
/file:"C:\Users\Yan\Scripts\UIPath\ExcelTest\ExcelTest.xaml" /executor /monitored
  • Replace the first location with the actual path of your UIPath Robot
  • Replace the second argument with the actual path of your xaml workflow
  • Save the file as a .bat file

Creating the task

Open up Task Scheduler and Create a Task.
  • On the Actions tab, add the script file you created
  • On the Triggers tab, setup the schedule you want for this task
That's it! The general idea is to be able to use Task Scheduler for running scheduled workflows instead of UIPath Orchestrator. I don't know the specifics about setting up a task but we only configured Triggers and Actions tab for this. 

:)
Share:

[Windows] How to open multiple apps at once using the run dialog

Basically what I want to do is launch several applications in one command. There are many options to do this. You can create a batch file that opens several applications then run it, or you can simply type a command from the run dialog that launches the apps you want.

I choose to do the latter because it's easier for me.

Here's the syntax. Suppose I want to launch Notepad, Calculator, and Task Manager in one go:


cmd /c start notepad & start calculator & start taskmgr
  • This command basically tells the computer to execute the program followed by the start command. 
  • The & allows you add multiple commands.
  • Remember to use the program's process name in order to launch them properly
Share:

[UIPath] Error: Programmatic access to Visual Basic Project is not trusted

If you encounter this error on UIPath saying "Programmatic access to Visual Basic Project is not trusted", it could mean that your MS Excel's Macro Trust Settings is disabled.


By default, Excel blocks any programmatic access to the application unless the user permits it. You may be invoking an external VBA macro file in your UIPath workflow that's causing this error. To enable trust settings, simply do the following:

  1. Open a blank workbook on MS Excel
  2. Got to File >> Options
  3. Click on Trust Center >> Trust Center Settings


  4. Click on Macro Settings >> Check ‘Trust Access to the VBA project object model’ (under Developer Macro Settings)


  5. Click OK to exit Trust Center window >> Then Click OK again to exit Excel Options window
Let me know if it worked! :)
Share:

[UIPath] Helpful VB expressions for date, string, and array/collection values

Here are my most commonly used VB expressions for handling date, string, and array/collection values. Will add more to these as I go along. UIPath activities essentially use VB.NET expressions so their API browser is extremely helpful in learning functions and syntax. .NET API Browser:
https://docs.microsoft.com/en-us/dotnet/api/?view=netframework-4.7.2

String

How to print new line on Message Box
Use vbCrLf
ie. "Hello" + vbCrLf + "World"

How to concatenate string and variable values
Use + operator
ie. "My name is " + var_name

How to split string value based on delimiter
Use the Split method to split a line of text into array values based on a delimiter
ie. Split("apple~bear~cat~dog","~") will return an array with 4 values.

To access them, you can loop through the array or for smaller and more defined formats you can simply retrieve the value based on its index number.

Split("apple~bear~cat~dog","~")(0) returns "apple"
Split("apple~bear~cat~dog","~")(1) returns "bear"
Split("apple~bear~cat~dog","~")(2) returns "cat"
Split("apple~bear~cat~dog","~")(3) returns "dog"

How to combine all array values into a string
Use the Join method
ie. var stringArray = {"Apple","Bear","Cat"}
String.Join("/",stringArray) will result to "Apple/Bear/Cat"

How to trim leading and trailing spaces from a text
Use the Trim method
ie. Trim("     This is a sentence    with lots of spaces.    ")
Note that Trim() removes only the spaces at the start and end, not the inside of the string.

How to replace certain characters in a string
Use the Replace method
ie. "apple~bear~cat~dog".Replace("~","!")
Replaces all instances of ~ with !, so that leaves me with "apple!bear!cat!dog"

Date/Time

How to format date value
Use ToString method
ie. Now.Date.ToString("MMMM yyyy")
will give to the current date displayed in this format: January 2018

For other custom date and time formats:
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

How to convert string value to DateTime format
Use Convert class
ie. Convert.ToDateTime("January 31, 2019")

For more details about the Convert class:

How to get first day of the month
Use the Date function and just format the day value as 1
ie. Now.Date.ToString("MMMM 1, yyyy")
will get you January 1, 2019

How to get last day of the month
Use AddMonths method to get the first day of the next month, then subtract 1 day using the AddDays method. 
ie. Convert.ToDateTime(Now.Date.ToString("MMMM 1, yyyy")).AddMonths(1).AddDays(-1).ToString("MMMM d, yyyy")
Will give you January 31, 2019 (relative to date today)

Note that you have to convert the first day of the month back to DateTime in order for the AddDays and AddMonths method to work.

Array/Collections

How to get all files in a folder
Use Directory.GetFiles method
ie. Directory.GetFiles("C:\Data\UIPath","*.*",SearchOption.AllDirectories) 
returns a String array of all the files inside the UIPath\ folder, including its subfolders, that matches the search pattern indicated in the 2nd argument.

"*.*" basically takes all types of files. "*.pdf " will get only files with the .pdf extension.
SearchOption.AllDirectories searches even the subdirectories under UIpath\

Because this method returns a String array, use a For loop to run through the collection.

For more info:
Share:

[UIPath] How to use Filter in Get Outlook Mail Messages Activity

The Filter property in Get Outlook Mail Messages allows you to set a filter for the messages to be retrieved from the specified mail folder.


Note that the Filter argument is for STRICT filters only. Meaning, wildcards and regex matches won't work. For example:

This filter retrieves messages received on the current month:
[ReceivedTime] >=' + Now.ToString("MM/01/yyyy") + "' AND [ReceivedTime] < '" + Now.AddMonths(1).ToString("MM/01/yyyy")+ "'"

This filter retrieves messages with the EXACT subject line 'Manila Downtime Advisory'
[Subject]='Manila Downtime Advisory'

Click here for more filter arguments you can use.
Share: