[Solved] Cell contents via Basic while cell is in input mode

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
brody
Posts: 7
Joined: Fri Dec 15, 2017 2:15 pm

[Solved] Cell contents via Basic while cell is in input mode

Post by brody »

[SOLVED]Hi:
Wrote the following to test zeroing out data in a group of cells.

Sub zeroOnButtonPress
xKtr = 0
yKtr = 0
oSheet = ThisComponent.getSheets().getByName("Sheet1")
for xKtr = 2 to 3
for yKtr = 6 to 9
oCell = oSheet.getCellByPosition(xKtr,yKtr)
oCell.value = 0
next
next
End Sub


During testing though, I noticed that if I started editing a cell - ie typing "asdf" into the cell, and then clicked on the button to run the macro, all of the cell values change EXCEPT the cell I was in edit mode with.

How do you force the cell out of edit mode prior to changing the data?

Thanks,
Brody
Last edited by brody on Fri Dec 15, 2017 5:50 pm, edited 2 times in total.
OpenOffice 4.1.4 on Windows 10
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Updating cell contents via Basic while cell is in input

Post by FJCC »

Here is an ugly hack that seems to work.

Code: Select all

Sub zeroOnButtonPress
oCntrl = ThisComponent.CurrentController

xKtr = 0
yKtr = 0
oSheet = ThisComponent.getSheets().getByName("Sheet1")

oCell = oSheet.getCellByPosition(0,0)
oCntrl.select(oCell)

for xKtr = 2 to 3
for yKtr = 6 to 9
oCell = oSheet.getCellByPosition(xKtr,yKtr)
oCell.value = 0
next
next
End Sub
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
brody
Posts: 7
Joined: Fri Dec 15, 2017 2:15 pm

Re: Updating cell contents via Basic while cell is in input

Post by brody »

Oh clever. Selecting a indifferent cell rather than DE-selecting the current one. I like this. Thank you so much!
OpenOffice 4.1.4 on Windows 10
Post Reply