Advertisement
drkbl

Get the selected cell in OO/LO Calc macro

Sep 30th, 2023
1,958
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Openoffice BASIC 1.46 KB | Source Code | 0 0
  1.         if theSelection.SupportsService("com.sun.star.sheet.SheetCell")  then
  2.             ' SINGLE CELL SELECTED
  3.             theCell=theSelection
  4.             msgbox "1/A Selected cell: " + theCell.RangeAddress.StartColumn + ":" + theCell.RangeAddress.StartRow
  5.             oActiveCell = ThisComponent.getCurrentSelection()
  6.             oConv = ThisComponent.createInstance("com.sun.star.table.CellAddressConversion")
  7.             oConv.Address = oActiveCell.getCellAddress
  8.             msgbox "1/B Cell Address: " + oConv.Address.Column + ":" + oConv.Address.Row
  9.         end if
  10.         if theSelection.SupportsService("com.sun.star.sheet.SheetCellRange")  then
  11.             ' RANGE OF CELLS SELECTED OR SINGLE CELL SELECTED
  12.             msgbox  "2 Selected cell in a range: " + theSelection.RangeAddress.StartColumn + ":" + theSelection.RangeAddress.StartRow + " - " + _
  13.                     theSelection.RangeAddress.EndColumn + ":" + theSelection.RangeAddress.EndRow
  14.         end if
  15.         activeSheet = ThisComponent.getCurrentController.getActiveSheet
  16.         theCell = UsedRange(activeSheet)
  17.         msgbox  "Used range: " + theCell.RangeAddress.StartColumn + ":" + theCell.RangeAddress.StartRow + " - " + _
  18.                 theCell.RangeAddress.EndColumn + ":" + theCell.RangeAddress.EndRow + "; " + _
  19.                 theCell.AbsoluteName
  20.  
  21. Function UsedRange(oSheet As Variant) As Variant
  22.     REM https://ask.libreoffice.org/t/looking-for-last-row-used-programmatically/26223/5
  23.     Dim oCursor As Variant
  24.     oCursor = oSheet.createCursor()
  25.     oCursor.gotoEndOfUsedArea(False)
  26.     oCursor.gotoStartOfUsedArea(True)
  27.     UsedRange = oCursor
  28. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement