Reputation: 69777
I have a button which launches a macro in OpenOffice. Within the macro, I want to change the name of the button. The original code for Excel is
ActiveSheet.Shapes("PunchButton").select
Selection.Characters.Text = "Punch In"
but the first line does nothing. I've checked the sheet in OpenOffice and the button has the right name. How do I get to it?
Upvotes: 1
Views: 4582
Reputation: 69777
Thanks to Pax, here's my working code. Not sure how robust it is, but for the sheet in question it works. Thanks again, Pax.
sub testThis
setButtonLabel("PunchButton", "hello")
setButtonLabel("ReportButton", "hello")
end sub
sub setButtonLabel(controlName, label)
oPage = ThisComponent.CurrentController.ActiveSheet.getDrawPage
iCount = oPage.getCount
For i = 0 to iCount - 1
oControl = oPage.getByIndex(i).getControl
If oControl.Name = controlName Then
oControl.label = label
exit sub
End If
Next
end sub
Upvotes: 0
Reputation: 882028
There's a snippet of code here that shows how to change the label and state of all buttons but the one you desire.
Sub clickCommandButton1
oPage = Thiscomponent.Sheets.getByName("Sheet1").getDrawPage
iCount = oPage.getCount
For i = 0 to iCount - 1
oEle = oPage.getByIndex(i)
oControl = oEle.getControl()
If oControl.DefaultControl = "com.sun.star.form.control.CommandButton" Then
' Found command button - change label of other buttons '
If oEle.Name <> "CommandButton1" Then
oControl.Label = "Inactive"
oControl.Enabled = False
End If
End If
Next
End Sub
I would modify this to iterate over all the buttons but change the internal if-statement to '=" instead of "<>" (and remove the disabling if that's not needed).
Upvotes: 2