Select cell to remove text insertion point

I have set up calc basic macros to load the contents of a cell (which is a partial account name) when I type Enter, look up the “full” version of the account name from a table, and then save the full version back into the cell. This works great when the cell is selected and there is not an active insertion point in the text of the cell. But if I select the cell, type the partial account name (so that the flashing insertion point bar is still in the cell), then press Enter, the code runs, but when I SetString on the cell, the text appears to be “locked” - since it’s being edited, I suppose - and the full version of the account name is NOT written back into the cell.

I tried selecting the cell before processing, but since it is already the active cell, selecting it appears to change nothing. I can select an adjacent cell, then go back to select the original cell, and then the code works fine, but I don’t have a reliable way to easily identify a cell on the page that I can select that I know won’t be locked. (And that’s kind of a kludge anyway.)

What I would really like is a method of a cell that would tell it to “finish” any current editing going on, so that when I SetString back into the cell, it will “take”. Does such a method exist? (I’m sure it most…) I have looked in the API documentation, but I find those docs kind of a mystery (and I’m a quite experienced programmer). I assume it would be related to SheetCell, but from that page where would I go to find what I need? (So an answer to my specific problem, but also a little bit of searching advice so that I can find my own answer in the future would both be 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?