emranali1989
New Member
- Joined
- Jun 15, 2020
- Messages
- 7
- Office Version
- 2010
- Platform
- Windows
Problem: I have a lock button (toggle button) on my custom ribbon. Basically "lock and unlock" the "Aspect ratio" of the text box.
Also i wanted few points to cover while preparing it - -
XML Code:
<customUI onLoad="RibbonUI_onLoad1" xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="customTab" label="WIP">
<group id="customGroup3" label="Organize">
<toggleButton id="MyToggleButton1" label="Lock" size="normal" imageMso="LockCell" onAction="Lock_and_Unlock" getPressed="GetPressed" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Code on Module:
'Callback for MyToggleButton1 onAction
Sub Lock_and_Unlock(control As IRibbonControl, pressed As Boolean)
ActiveWindow.Selection.ShapeRange.LockAspectRatio = msoTriStateToggle
End Sub
Code on Class Module(very much unsure)
Private Sub App_WindowSelectionChange(ByVal Sel As Selection)
'Handles Application.WindowSelectionChange
'ActiveWindow.Selection.ShapeRange.LockAspectRatio = msoTriStateToggle
MsgBox "selection change1"
If Application.ActiveWindow.Selection.ShapeRange = ppSelectionShapes Then
If Application.ActiveWindow.Selection.ShapeRange.LockAspectRatio = msoTrue Then
MsgBox "lock"
Else
MsgBox "unlock"
End If
End If
Dim oRibbon As IRibbonUI
Set oRibbon = MainModule.gb_oMyRibbon1
oRibbon.InvalidateControl "MyToggleButton1"
End Sub
Also i wanted few points to cover while preparing it - -
- I wanted to run the event on powerpoint, whenever I select the single or multiple text boxes/shape/image, if its aspect ratio is already locked then my "Lock" button need to highlight in the ribbon. vice versa
- If I select multiple text boxes/shape/images with few's aspect ratio are lock and few's aspect ratio are unlock, then it must unhighlight the "lock" button in the ribbon.
XML Code:
<customUI onLoad="RibbonUI_onLoad1" xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="customTab" label="WIP">
<group id="customGroup3" label="Organize">
<toggleButton id="MyToggleButton1" label="Lock" size="normal" imageMso="LockCell" onAction="Lock_and_Unlock" getPressed="GetPressed" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Code on Module:
'Callback for MyToggleButton1 onAction
Sub Lock_and_Unlock(control As IRibbonControl, pressed As Boolean)
ActiveWindow.Selection.ShapeRange.LockAspectRatio = msoTriStateToggle
End Sub
Code on Class Module(very much unsure)
Private Sub App_WindowSelectionChange(ByVal Sel As Selection)
'Handles Application.WindowSelectionChange
'ActiveWindow.Selection.ShapeRange.LockAspectRatio = msoTriStateToggle
MsgBox "selection change1"
If Application.ActiveWindow.Selection.ShapeRange = ppSelectionShapes Then
If Application.ActiveWindow.Selection.ShapeRange.LockAspectRatio = msoTrue Then
MsgBox "lock"
Else
MsgBox "unlock"
End If
End If
Dim oRibbon As IRibbonUI
Set oRibbon = MainModule.gb_oMyRibbon1
oRibbon.InvalidateControl "MyToggleButton1"
End Sub