2014-10-20 25 views
1

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

实施例的代码,其用于自定义功能区:

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

THX。

回答

3

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

<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回调,以便在需要时可以使控件/功能区无效。

+0

非常感谢。 – NoChance 2014-10-21 12:25:46

相关问题