# Revision history [back]

I finally found the answer to my own question, based on the helpful information from ms777 at http://www.oooforum.org/forum/viewtopic.phtml?t=32036.

Here is the code I ended up with, which checks to see if the user is in edit mode (i.e. there is an active cursor in the cell), and if so attempt to cancel out of it.

' Check to see if we are in edit mode (with active cursor in the cell)
oAC = ThisComponent.CurrentController.Frame.ComponentWindow.accessibleContext
oACToolbar = oAC.getAccessibleChild(1).accessibleContext
oACSumCancel = oACToolbar.getAccessibleChild(3)
sName = oACSumCancel.AccessibleName
If sName <> "Sum" Then
' we are in edit mode, attempt to get out of it or else we can't modify the cell
oACFunctionAccept = oACToolbar.getAccessibleChild(4)
oACFunctionAccept.grabFocus
oACFunctionAccept.doAccessibleAction(0)
End If


I have to admit that I am still relying on code snippets that I find in Google searches for most of my LO macro code. I would have been VERY hard pressed to come up with the code above by looking at the API documentation. Does anyone else feel that way? I've tried to read through any pages I find that try to explain how to work with the API, or how to "think" when programming LO macros, but the light bulb has yet to turn on. I've read Andrew's document and lots of web pages, and I find lots of helpful information... but I'm not really capable of going beyond by digging into the API (and it seems like there is a LOT of beyond!). Any suggestions for further reading or research to help me get beyond this block would be greatly appreciated.

Thanks, Jeff

I finally found the answer to my own question, based on the helpful information from ms777 at http://www.oooforum.org/forum/viewtopic.phtml?t=32036.

Here is the code I ended up with, which checks to see if the user is in edit mode (i.e. there is an active cursor in the cell), and if so attempt to cancel out of it.

' Check to see if we are in edit mode (with active cursor in the cell)
oAC = ThisComponent.CurrentController.Frame.ComponentWindow.accessibleContext
oACToolbar = oAC.getAccessibleChild(1).accessibleContext
oACSumCancel = oACToolbar.getAccessibleChild(3)
sName = oACSumCancel.AccessibleName
If sName <> "Sum" Then
' we are in edit mode, attempt to get out of it or else we can't modify the cell
oACFunctionAccept = oACToolbar.getAccessibleChild(4)
oACFunctionAccept.grabFocus
oACFunctionAccept.doAccessibleAction(0)
End If


I have to admit that I am still relying on code snippets that I find in Google searches for most of my LO macro code. I would have been VERY hard pressed to come up with the code above by looking at the API documentation. Does anyone else feel that way? I've tried to read through any pages I find that try to explain how to work with the API, or how to "think" when programming LO macros, but the light bulb has yet to turn on. I've read Andrew's document and lots of web pages, and I find lots of helpful information... but I'm not really capable of going beyond by digging into the API (and it seems like there is a LOT of beyond!). Any suggestions for further reading or research to help me get beyond this block would be greatly appreciated.

Thanks, Jeff

This code is generally working well, and after it is run, I can modify the contents of the cell that was being edited previously. But when control is returned to the user, the "focus" is still up in the toolbar. Can someone tell me how to get the focus back on the spreadsheet? I tried a selection, but the focus seems to be a different thing than the selection. And if the focus is up in the toolbar, when the user types the arrow keys or Enter, the results aren't what he expects, since they are acting up the toolbar. So how do I set focus back on the spreadsheet?