What means "current cell"? Cell with calculated formula at now? Or active cell (outlined bold border)?
REM Function to determine the active cell
REM Parameters:
REM iSheet - the index of the sheet to which the active cell is searched.
REM Isn't required. By default - the active sheet
REM oDoc - workbook, for which the active cell is searched.
REM Isn't required. Default - the current document
REM Returns a reference to the active cell (or Null if it isn't possible to determine)
REM Author: Vladislav Orlov aka JohnSUN, Ukraine, Kiev, 2012
REM by UROS> http://www.oooforum.org/forum/viewtopic.phtml?t=19348
REM by Villeroy> http://user.services.openoffice.org/en/forum/viewtopic.php?f=20&t=38672 # p177590
Function ActiveCell (Optional iSheet As Long, Optional oDoc As Variant) As Object
Dim arrayOfString () ' An array of text strings to parse
Dim lRow&, lColumn& ' The coordinates of the desired cell
Dim tmpString$ ' Time line
Dim oCurrentController ' controller of the analyzed document
Dim oSheets As Variant ' All the pages of the current book
Dim oSheet As Variant ' Active (test) page of the book
REM Check input parameters and set the default values :
If IsMissing (oDoc) Then oDoc = ThisComponent
If NOT oDoc.SupportsService ("com.sun.star.sheet.SpreadsheetDocument") Then Exit Function
oCurrentController = oDoc.getCurrentController()
If IsMissing (iSheet) Then
oSheet = oCurrentController.getActiveSheet()
iSheet = oSheet.getRangeAddress().Sheet
Else
If (iSheet < 0) Then Exit Function
oSheets = ThisComponent.getSheets()
If (iSheet>= oSheets.getCount ()) Then Exit Function
oSheet = oSheets.getByIndex (iSheet)
EndIf
tmpString = oCurrentController.getViewData()
arrayOfString () = Split (tmpString, ";")
If UBound (arrayOfString) <( 3 + iSheet) Then Exit Function
tmpString = arrayOfString ( 3 + iSheet)
If InStr (tmpString, "+")> 0 Then
arrayOfString () = Split (tmpString, "+")
Else
arrayOfString () = Split (tmpString, "/")
EndIf
lColumn = CLng (arrayOfString ( 0) )
lRow = CLng (arrayOfString ( 1) )
Set ActiveCell = oSheet.getCellByPosition (lColumn, lRow)
End Function