PowerPoint VBA/Custom UI XML: toggle/checkbox getPressed dynamic update

Viewed 56

I am trying to include a button for both textwrapping for textboxes and locking the aspect ratio of a shape. I am able to get the buttons to work on its own but I can't seem to get the getPressed value to reflect the initial state of the shape.

i.e. if a shape already have .LockAspectRatio = True, and i select it, the custom button's getPressed attibute doesn't change to True. The sub still runs when I press the button, it's a simple line of .LockAspectRatio = not .LockAspectRatio, but it just looks silly having the button on the ribbon shown as 'pressed', but the actual attibute for the shape is False.

My question is how do I get the getPressed value to reflect the shape's intial value, and have this shown in the ribbon.

I've gathered from other posts that there is need for a sub to address the ribbon but I am unsure of the purpose of this, below is what I have so far.

Option Explicit

Public isPressed As Boolean
Public myRibbon As IRibbonUI

Sub toggleAR(ribbon As IRibbonUI)
    
    Set myRibbon = ribbon
        
End Sub

Sub getPressedAR(control As IRibbonControl, ByRef returnedVal)

    Select Case control.Id
        Case "AspectRatio"
            returnedVal = isPressed
    End Select

End Sub

Sub AspectRatio(control As IRibbonControl, pressed As Boolean)
    
    Select Case control.Id
        Case "AspectRatio"
            If ActiveWindow.Selection.ShapeRange.LockAspectRatio = msoTrue Then
                isPressed = True
            Else
                isPressed = False
            End If
            ActiveWindow.Selection.ShapeRange.LockAspectRatio = Not ActiveWindow.Selection.ShapeRange.LockAspectRatio
    End Select
    
End Sub

Thanks in advance

0 Answers
Related