VBA Ribbon getPressed用于toggleButton

时间:2016-11-20 08:58:04

标签: vba ribbon

我正在尝试设置toggleButton的值。这是我的Ribbon XML

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
 <ribbon startFromScratch="false">
  <tabs>
   <tab id="customTab" label="CC">
    <group id="grpSegments" label="Segments">
     <dropDown id="cbLeaves" label="Segments" onAction="LeavesChanged" getSelectedItemID="GetCBLeavesSelectedID">
      <item id='item4' label='4'/>
      <item id='item6' label='6'/>
      <item id='item8' label='8'/>
      <item id='item12' label='12'/>
     </dropDown>
     <button id="cGenerate" label="Generate" size="large" onAction="ArrangeRosette"/>
    </group>
    <group id="grpGuides" label="Guides">
     <toggleButton id="cToggleGuide" label="Show Guides" onAction="GuideToggled" getPressed="GetGuideState"/>
    </group>
   </tab>
  </tabs>
 </ribbon>
</customUI>

我有一个带签名的方法

Sub GuideToggled(control As IRibbonControl, ByRef Pressed As Boolean)

但是,这总是会导致无法访问宏的错误。

然而,dropDown的getSelectedItemID没有问题

Sub GetCBLeavesSelectedID(control As IRibbonControl, ByRef ItemID As Variant)

我找不到任何记录了getPressed回调的资源。

2 个答案:

答案 0 :(得分:2)

您在功能区XML中引用GuideToggledGetGuideState,因此您需要它们:

'Callback for cToggleGuide onAction
Sub GuideToggled(control As IRibbonControl, pressed As Boolean)
End Sub

'Callback for cToggleGuide getPressed
Sub GetGuideState(control As IRibbonControl, ByRef returnedVal)
End Sub

你试过custom UI editor tool吗?它将帮助您找到适合您的VBA回调的签名。

答案 1 :(得分:0)

试试这个

Callback for HighlightTBtn onAction
Sub GoTo_onAction(control As IRibbonControl, pressed As Boolean)
MsgBox pressed
If pressed Then
MsgBox "Button On"
Else
MsgBox "Button Off"
End If
End Sub