Page 1 of 1
[Solved] Simple Set CheckBox to True or False
Posted: Tue Apr 10, 2018 9:08 am
by alb21
I will appretiate very much if you guys can help me get started with oo basic programming. I've done quite a bit of excel macro programming and I am trying to move to OpenOffice but nothing seems to work. I copied this code from OpenOffice wiki but I get the following error pointing to the "oControl = oForm.getByName..." line
Basic runtime error.
An exception ocurred
Type: com.sun.star.container.NoSuchElementException
Message: .
Code: Select all
Sub SetMyCheckBox
Dim oForm
Dim oControl
Dim oSheet
Dim oCell
oForm = ThisComponent.Sheets(0).DrawPage.Forms.getByIndex(0)
oControl = oForm.getByName("MyCheckbox")
oSheet = ThisComponent.Sheets(0)
oCell = oSheet.getCellRangeByName("A1")
If oCell.Value = "1" then
oControl.Value = "True"
Else
oControl.Value = "False"
End If
End Sub
All I have in my spreadsheet is a CheckBox labeled and named "MyCheckBox"
Re: Simple Set CheckBox to True or False
Posted: Tue Apr 10, 2018 12:08 pm
by Zizi64
Please download, install and use one of the existing object inspection tools, like the XrayTool or the MRI. Then you will able to examine the properties, methods of the programming objects.
Re: Simple Set CheckBox to True or False
Posted: Tue Apr 10, 2018 5:21 pm
by UnklDonald418
All I have in my spreadsheet is a CheckBox labeled and named "MyCheckBox"
but your macro code
Code: Select all
oControl = oForm.getByName("MyCheckbox")
the lower case "b" in your macro is the reason getByName() can't find the control.
If you are going to do much macro programming then follow the advice of
Zizi64
[Tutorial] Introduction into object inspection with MRI
Re: Simple Set CheckBox to True or False
Posted: Tue Apr 10, 2018 6:44 pm
by Villeroy
Simply link the check box to A1 or SheetName.A1
Re: Simple Set CheckBox to True or False
Posted: Wed Apr 11, 2018 5:50 am
by alb21
I appretiate very much your advice. The uppercase "B" got rid of the error message of my initial question (my mistake), now the error message is in the line:
"oControl.Value = ..." Property or method not found: Value.
which I find very surprising as this code was copied from OpenOffice wiki (my only addition was creating the CheckBox on the spreadsheet).
At this moment I am downloading and installing Xray, and reading the Guides suggested by Zizi64 . After that I'll go into MRI. My hope is to finally figure out why Value is not found and what are the correct and valid names of the properties and methods I need for my purposes.
[Solved] Simple Set CheckBox to True or False
Posted: Wed Apr 11, 2018 6:11 am
by alb21
I changed my line: "oControl.Value = "True"
by this new form: "oControl.State = 1"
and problem solved. I found the correct and valid names I needed in the Basic Guide, Control Element Forms in Detail, here:
https://wiki.openoffice.org/wiki/Docume ... ment_Forms
Thanks again
Re: [Solved] Simple Set CheckBox to True or False
Posted: Wed Apr 11, 2018 7:08 am
by Zizi64
I found the correct and valid names I needed in the Basic Guide, Control Element Forms in Detail, here:
The XrayTool can list all of the Properties, Methods, Services, Interfaces and Listeners "in situ".
Here is an example with a shape Object: