ActiveDatasheet Property Example

The following example uses the ActiveDatasheet property to identify the datasheet cell with the focus, or if more than one cell is selected, the location of the first row and column in the selection.

Sub GetSelection()
    Dim objDatasheet As Object
    Dim lngFirstRow As Long, lngFirstColumn As Long
    Const conNoActiveDatasheet = 2484
    On Error GoTo GetSelection_Err
    Set objDatasheet = Screen.ActiveDatasheet
    lngFirstRow = objDatasheet.SelTop
    lngFirstColumn = objDatasheet.SelLeft
    MsgBox "The first item in this selection is located at " _
        & "Row " & lngFirstRow & ", Column " & lngFirstColumn
GetSelection_Bye:
    Exit Sub
GetSelection_Err:
    If Err = conNoActiveDatasheet Then
        Resume GetSelection_Bye
    End If
End Sub