Search code examples
vbaribbon

VBA Ribbon getPressed for a toggleButton


I am trying to set the value of a toggleButton. This is my 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>

I have a method with the signature

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

However, this always results in an error about macro not being accessible.

whereas, the getSelectedItemID for the dropDown has no trouble

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

I cannot find any resource which has the getPressed callback documented.


Solution

  • You reference GuideToggled and GetGuideState in your ribbon XML, so you need them both:

    '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
    

    Have you tried the custom UI editor tool? It will help you find the right signatures for your VBA callbacks.