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

Thanks,
Shohei,

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)

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

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)

3 Likes

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
Try
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)
excel.Visible=True
End Try
ws=CType(wb.Sheets(“Output”),Microsoft.Office.Interop.Excel.Worksheet)
‘ws.Range(“D3:E3”).Copy()’
ws.Range(“C14”).Copy
s=excel.ActiveCell.Address()

1 Like