2014-10-20 23 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

相關問題