In screenshot 2, the range is selected (and highlighted) with the mouse, in screenshot 1 - with a macro (not highlighted).
Code: Select all
Function getCurrentRegion(oRange As Object)
Dim oCursor As Object
oCursor = oRange.Spreadsheet.createCursorByRange(oRange) '.getSpreadsheet()
' Expand the cursor into the region containing the cells to which
' it currently points. A region is a cell range bounded by empty cells.
oCursor.collapseToCurrentRegion()
getCurrentRegion = oCursor
End Function
Sub test_CurrentRegion()
Dim view, sel, rg, addr
view = ThisComponent.CurrentController '.getCurrentController() -> ScTabViewObj
sel = view.Selection '.getSelection()
If sel.supportsService("com.sun.star.sheet.SheetCellRange") Then
rg = getCurrentRegion(sel)
addr = rg.RangeAddress
'Call report(addr, "CurrentRegion")
view.select(rg) '***selects but not highlights***
Else
MsgBox "No single cell or range selected"_
, MB_ICONEXCLAMATION, "Selection Error"
End If
End Sub