如何寻址按钮? (OpenOffice 电子表格宏)

发布于 2024-07-13 19:12:06 字数 245 浏览 7 评论 0原文

我有一个在 OpenOffice 中启动宏的按钮。 在宏中,我想更改按钮的名称。 Excel 的原始代码是,

    ActiveSheet.Shapes("PunchButton").select
    Selection.Characters.Text = "Punch In"

但第一行什么也不做。 我已经检查了 OpenOffice 中的工作表,按钮的名称正确。 我怎样才能到达它?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花期渐远 2024-07-20 19:12:06

此处有一段代码,展示了如何更改标签和除您想要的按钮之外的所有按钮的状态。

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 语句更改为“=”而不是“<>”(如果不需要,则删除禁用)。

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).

旧时光的容颜 2024-07-20 19:12:06

感谢 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文