I thought shifting the focus from the ‘currently entering data cell’ would
cure the problem and it does, but seems inelegant.
What I’d really like to do is have the computer know which cell was the one that is currently
and/or which cell was the last opened so that the code can run and examine that cells contents.
Sub Check_if_A1_is_number
mySheet=ThisComponent.CurrentController.ActiveSheet
myCell = mySheet.getCellRangeByName("B1")
ThisComponent.CurrentController.select(myCell)
myCell = mySheet.getCellRangeByName("A1")
ThisComponent.CurrentController.select(myCell)
rem ^^^ trying to 'close' the "active data entry" mode of cell A1
rem by shifting focus to cell B2 (and then shifting back to A1
rem It works.
cellA1 = mySheet.getCellrangeByName("A1")
cellA2 = mySheet.getCellrangeByName("A2")
If IsNumeric(cellA1.getString()) Then
cellA2.setString("It is a number")
Else
cellA2.setString("It's not a number at all!!!")
EndIF
End Sub
=====================
If like me and you are quite new to LO BASIC programming, you may have noticed there a couple of
ways in which code can be run. Here is an alternative using the feared ‘dispatcher’. Hope you find both methods useful.
sub Write_in_A1
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "$B$1"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
rem ----------------------------------------------------------------------
rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "ToPoint"
args2(0).Value = "$A$1"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())
rem ----------------------------------------------------------------------
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "StringName"
args3(0).Value = "Hi LibreOffice_Mike"
dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args3())
rem ----------------------------------------------------------------------
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "ToPoint"
args4(0).Value = "$C$3"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args4())
rem ----------------------------------------------------------------------
end sub