VBA 切换按钮的功能区 getPressed

VBA Ribbon getPressed for a toggleButton

我正在尝试设置 toggleButton 的值。这是我的丝带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)

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

然而,下拉列表的 getSelectedItemID 没有问题

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

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

您在功能区 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 回调找到正确的签名。

试试这个

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