Basic code for Calc coming with an object named oActiveCell
or similar should be suspected to be part of an attempt to get copied and pasted code written in Excel VBA to work.
Actually Excel VBA has such a (function? predefined variable? something?) available for any “workbook”. What a Calc user will get from ThisComponent.CurrentSelection
will return the cell the Excel programmer had in mind in many cases, but also often something else. Even the precautions suggeseted by @JohnSUN will not always get the cell currently having the keyboard focus what is what ActiveCell
means in VBA.
LibreOffice Basic used for a Calc document has no simple way to access the mentioned cell.
The simplest way to get it I knoiw of goes back to times when a user “uros” posted elsewhere, and @Villeroy preserved his hints. Try:
currCtrl = ThisComponent.CurrentController
currVD = currCtrl.ViewData
currSheet = currCtrl.ActiveSheet
vDSplit = Split(currVD, ";")
currSNum = currSheet.RangeAddress.Sheet
sInfo = vDSplit(currSNum + 3)
REM For CellAddress.Row >= 8192 the "+" is used as the subdelimiter in ViewData. WHY?
If InStr(sInfo, "+")>0 Then
sInfoDelim = "+"
Else
sInfoDelim = "/"
End If
sInfoSplit = Split(sInfo, sInfoDelim)
currFocusCell = currSheet.GetCellByPosition(sInfoSplit(0), sInfoSplit(1))
To re-nestle into VBA, you may name the variable ActiveCell
instead of using the more speaking currFocusCell
I suggested above…
Recent LibO Basic under Option VBAsupport 1
has the ActiveCell
thing, too, but the usage of that option may well also come with disadvantages. As always: Be careful! Careless programming is a way to hell.