Get the selected cell in OO/LO Calc macro
drkbl |
PRO |
09/30/23 08:43:13 PM UTC |
0 ⭐ |
12820 👁️ |
Never ⏰ |
[calc, libreoffice, OpenOffice, Selected cell]
if theSelection.SupportsService("com.sun.star.sheet.SheetCell") then
' SINGLE CELL SELECTED
theCell=theSelection
msgbox "1/A Selected cell: " + theCell.RangeAddress.StartColumn + ":" + theCell.RangeAddress.StartRow
oActiveCell = ThisComponent.getCurrentSelection()
oConv = ThisComponent.createInstance("com.sun.star.table.CellAddressConversion")
oConv.Address = oActiveCell.getCellAddress
msgbox "1/B Cell Address: " + oConv.Address.Column + ":" + oConv.Address.Row
end if
if theSelection.SupportsService("com.sun.star.sheet.SheetCellRange") then
' RANGE OF CELLS SELECTED OR SINGLE CELL SELECTED
msgbox "2 Selected cell in a range: " + theSelection.RangeAddress.StartColumn + ":" + theSelection.RangeAddress.StartRow + " - " + _
theSelection.RangeAddress.EndColumn + ":" + theSelection.RangeAddress.EndRow
end if
activeSheet = ThisComponent.getCurrentController.getActiveSheet
theCell = UsedRange(activeSheet)
msgbox "Used range: " + theCell.RangeAddress.StartColumn + ":" + theCell.RangeAddress.StartRow + " - " + _
theCell.RangeAddress.EndColumn + ":" + theCell.RangeAddress.EndRow + "; " + _
theCell.AbsoluteName
Function UsedRange(oSheet As Variant) As Variant
REM https://ask.libreoffice.org/t/looking-for-last-row-used-programmatically/26223/5
Dim oCursor As Variant
oCursor = oSheet.createCursor()
oCursor.gotoEndOfUsedArea(False)
oCursor.gotoStartOfUsedArea(True)
UsedRange = oCursor
End Function
Comments
0 B
|👍
/👎
0 B
|👍
/👎