SelHeight, SelWidth, SelTop, and SelLeft Properties Example
The following example shows how to use the SelHeight, SelWidth, SelTop, and SelLeft properties to determine the position and size of a selection rectangle in datasheet view. The SetHeightWidth procedure assigns the height and width of the current selection rectangle to the variables lngNumRows
, lngNumColumns
, lngTopRow
, and lngLeftColumn
, and displays those values in a message box.
Sub SetHeightWidth(frm As Form)
Dim lngNumRows As Long, lngNumColumns As Long
Dim lngTopRow As Long, lngLeftColumn As Long
Dim strMsg As String
If frm.CurrentView = 2 Then 'Form is in Datasheet view.
lngNumRows = frm.SelHeight 'Number of rows selected.
lngNumColumns = frm.SelWidth 'Number of columns
' selected.
lngTopRow = frm.SelTop 'Topmost row selected.
lngLeftColumn = frm.SelLeft 'Leftmost column
' selected.
strMsg = "Number of rows: " & lngNumRows & vbCrLf
strMsg = strMsg & "Number of columns: " _
& lngNumColumns & vbCrLf
strMsg = strMsg & "Top row: " & lngTopRow & vbCrLf
strMsg = strMsg & "Left column: " & lngLeftColumn
MsgBox strMsg
End If
End Sub