[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: