How to get active cell address from Excel

excel

#1

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.
excelcelladdress

Thanks,
Shohei,


#2

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


#3

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)

    Runtime.InteropServices.Marshal.ReleaseComObject(xSel)
    Runtime.InteropServices.Marshal.ReleaseComObject(xAp)
    Runtime.InteropServices.Marshal.ReleaseComObject(xBk)

I hope this helps somebody.


#4

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