How to get active cell address from Excel

How to get active cell address ?
My work environment can’t use Excel macro.
I’d like to get that with the function of Uipath.


1 Like

One of the easiest ways is to Perform a Click on the cell address bar and copy the value. However, the clipboard activity was not storing this value for me. If you face the same issue, you can paste it into a notepad and do a get text for it.

You can also check How to find a Excel cell address dynamically and write content

Today I faced same problem, and wrote a short VB.NET Code.

At first, you need add “Invoke Code” Activity, and set two arguments.
First argument is WorkbookFileName as String, it should set Excel workbook full file path.
Fortunately, we can get filename from variable of Excel Application Scope, Do like this.

Second argument is Result, it’s output of this function. It’s string type, like “A1” or “B5:C10” style.

The VB.NET Code is this:
Dim flags As Reflection.BindingFlags = Reflection.BindingFlags.GetProperty Or Reflection.BindingFlags.Instance

    Dim xBk As Object = GetObject(WorkbookFileName)
    Dim xAp As Object = xBk.GetType().InvokeMember("Application", flags, Nothing, xBk, Nothing)
    Dim xSel As Object = xAp.GetType().InvokeMember("Selection", flags, Nothing, xAp, Nothing)
    Result = xSel.GetType().InvokeMember("Address", flags, Nothing, xSel, Nothing).ToString().Replace("$", String.Empty)


I hope this helps somebody.

here you are, pure activity.
tested on Excel 2016, not sure if it could generalize on all Excel versions.
getcell.xaml (10.3 KB)


Hey @Honoka
I am using below code for getting cell reference/address but it’s not working and throwing error:
Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
Dim rng As Microsoft.Office.Interop.Excel.Range
Dim s As String
wb = DirectCast(GetObject(Path),Microsoft.Office.Interop.Excel.Workbook)
Catch ex As Exception
excel = DirectCast(CreateObject(“Excel.Application”), Microsoft.Office.Interop.Excel.Application)
wb = excel.Workbooks.Open(Path)
End Try

1 Like