Ian Botham
Ian Botham

Reputation: 139

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.

Upvotes: 1

Views: 7254

Answers (2)

geroge lee
geroge lee

Reputation: 1

Try this

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

Upvotes: 0

Olle Sj&#246;gren
Olle Sj&#246;gren

Reputation: 5385

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.

Upvotes: 4

Related Questions