【问题标题】:How to change the label value on Excel 2007 ribbon programatically when Worksheet is opened打开工作表时如何以编程方式更改 Excel 2007 功能区上的标签值
【发布时间】:2014-10-21 15:35:57
【问题描述】:

在 Excel 2007 功能区上,我添加了一个带有按钮的新组。我需要能够根据第一次打开工作表时检查的条件(例如 onload 事件)将标签文本从“ABC_Execute”更改为“其他内容” - 如何在 VBA 中执行此操作?

用于自定义功能区的示例代码:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
    <ribbon>
        <tabs>
            <tab id="customTab" label="ABC" insertAfterMso="TabHome">
                <group id="customGroup" label="ABC Tools">
                    <button id="customButton1" label="ABC_Execute" size="large" onAction="Begin" imageMso="Bold" />
                </group>
            </tab>
        </tabs>
    </ribbon>
</customUI>

谢谢。

【问题讨论】:

    标签: excel ribbon vba


    【解决方案1】:

    您需要为您的 CustomUI 添加一个 getLabel 回调:

    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="rx_rib_on_load">
        <ribbon>
            <tabs>
                <tab id="customTab" label="ABC" insertAfterMso="TabHome">
                    <group id="customGroup" label="ABC Tools">
                        <button id="customButton1" getLabel="rx_getLabel" size="large" onAction="Begin" imageMso="Bold" />
                    </group>
                </tab>
            </tabs>
        </ribbon>
    </customUI>
    

    然后在工作簿模块中:

    Sub rx_getLabel(control As IRibbonControl, ByRef returnedVal)
        returnedVal = ThisWorkbook.Sheets("Sheet1").Range("A1").Value
    End Sub
    

    例如。如果您需要随后更改该值,您将需要一个 onLoad 回调,以便您可以在需要时使控件/功能区无效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-29
      • 1970-01-01
      • 2015-10-15
      相关资源
      最近更新 更多