我有一个在OpenOffice中启动宏的按钮。在宏中,我想更改按钮的名称。 Excel的原始代码是
ActiveSheet.Shapes("PunchButton").select
Selection.Characters.Text = "Punch In"
但第一行什么也没做。我在OpenOffice中检查了工作表,按钮的名称正确。我怎么做到的?
答案 0 :(得分:2)
有一段代码here,其中显示了如何更改所有按钮的标签和状态,而不是您想要的按钮。
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
我会修改它以迭代所有按钮,但将内部if语句更改为“=”而不是“&lt;&gt;”(并删除禁用,如果不需要)。
答案 1 :(得分:0)
感谢Pax,这是我的工作代码。不确定它有多强大,但对于有问题的纸张它是否有效。再次感谢,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