I need to retrieve the color of a cell

I need to retrieve the color of a cell in Excel using UiPath. However, the native UiPath activities are not working properly for this, so I’m considering using VBA code instead. What do you recommend?

Thanks.

Hello.

Download Import Microsoft.Office.Interop.Excel
image

Use “Use Excel File”

Inside of the assign:

Replace “A1” with the cell you need to grab the color of. The output:
image

1 Like

You can not use Invoke vb code activity in modern to achieve this you need to use both:

How to Use Modern and Classic Excel Activities Together:

Step to Enable Classic Activities

  1. In the Activities panel, click the Filter icon (funnel).

  2. Check the box: :white_check_mark: Show Classic.
    Now you’ll see both Modern and Classic Excel activities.

Create your VBA script:
Here’s a simple VBA code to get the interior (background) color of a cell:

  1. Below vb scripts:
    Function GetCellColor(cellAddress As String) As Long
    GetCellColor = Range(cellAddress).Interior.Color
    End Function
  2. Save this code to a file named like GetCellColor.vb (you can just use .txt and rename to .vb if needed).
  3. Use “Invoke VBA” activity in UiPath:Place it inside Excel Application Scope.
    4.Invoke VBA" activity in UiPath:
    5.Place it inside Excel Application Scope.
    6.Set:Code File Path: path to your .vb file.

EntryMethodName: GetCellColor

EntryMethodParameters: { “A1” } (or any cell reference)

Output: assign to a variable of type Int32 or Long. It will return the RGB integer of the color (e.g., 16777215 for white).
Optional: Convert Integer to RGB
If you want RGB components:

R = ColorValue Mod 256
G = (ColorValue \ 256) Mod 256
B = (ColorValue \ 65536) Mod 256

Hi @nicol-dayana.arias-lebro ,

Option 1: Have you tried using Get cell color activity?

Option 2: VBA code
Function GetCellColor(cellAddress As String) As Long
GetCellColor = Range(mentionCellAddress).Interior.Color
End Function

Dim colorInt As Long = GetCellColor(“A1”) // lets say above function got the “A1” cell
Dim colorObj As Color = ColorTranslator.FromOle(colorInt)
Dim colorName As colorName = colorObj.Name

I have given you two options, try any and let me know your result.

i use option 1 cause it works for me. but option is also good and faster.

If it helped then kindly mark this as solution.