Lock button in Powerpoint Custom Ribbon

emranali1989

New Member
Joined
Jun 15, 2020
Messages
7
Office Version
  1. 2010
Platform
  1. 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 - -
  • 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.
I am just unclear what to write in the event. pls help


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
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Welcome



The code below toggles the state of a single shape; next step is to make the ribbon button react to slide selections.

VBA Code:
'Callback for MyToggleButton1 onAction

Sub Lock_and_Unlock(control As IRibbonControl, pressed As Boolean)
Dim sh As ShapeRange
Set sh = ActiveWindow.Selection.ShapeRange
MsgBox sh.LockAspectRatio, , sh.Name & " initial state"
Select Case sh.LockAspectRatio
    Case msoTrue
        sh.LockAspectRatio = msoFalse
    Case msoFalse
        sh.LockAspectRatio = msoTrue
End Select
MsgBox sh.LockAspectRatio, , sh.Name & " new state"
End Sub
 
Upvote 0
Hello, Thanks for asking.
Yet i have not able to complete the above task. It would be great help if you could help me on this.
Thanks
 
Upvote 0
This is the event part:

VBA Code:
'PowerPoint class module named EventClass

Public WithEvents PPTEvent As Application

Private Sub Class_Terminate()
MsgBox "EventHandler is now inactive.", vbInformation + vbOKOnly, _
"PowerPoint Event Handler Example"
End Sub

Private Sub PPTEvent_WindowSelectionChange(ByVal Sel As Selection)
If Sel.Type = ppSelectionShapes Then _
MsgBox Sel.ShapeRange.LockAspectRatio, 64, "Lock status"
End Sub

Private Sub Class_Initialize()
MsgBox "The EventHandler class has been initialized."
End Sub

VBA Code:
' Powerpoint standard module
Dim cPPTObject As New EventClass, TrapFlag As Boolean
Sub TrapEvents()
MsgBox "Trapping event..."
If TrapFlag = True Then
    MsgBox "the EventHandler is already active.", _
    vbInformation + vbOKOnly, "PP Event Handler"
    Exit Sub
End If
Set cPPTObject.PPTEvent = Application
TrapFlag = True
End Sub

Sub ReleaseTrap()
If TrapFlag = True Then
    Set cPPTObject.PPTEvent = Nothing
    Set cPPTObject = Nothing
    TrapFlag = False
End If
End Sub
 
Upvote 0
Thanks again for the big help.
I am receiving compile error. Pls find the attached images. Pls check.
 

Attachments

  • Class.png
    Class.png
    134.4 KB · Views: 23
  • Complie Error.png
    Complie Error.png
    176.8 KB · Views: 39
  • Module.png
    Module.png
    164.9 KB · Views: 33
Upvote 0
This example shows how the ribbon can recognize what is happening on the slides:

PP_ribbon.PNG


VBA Code:
'PowerPoint class module named EventClass

Public WithEvents PPTEvent As Application

Private Sub Class_Terminate()
MsgBox "EventHandler is now inactive.", vbInformation + vbOKOnly, _
"PowerPoint Event Handler Example"
End Sub

Private Sub PPTEvent_WindowSelectionChange(ByVal Sel As Selection)
If Sel.Type = ppSelectionShapes Then
    pv = Sel.ShapeRange.LockAspectRatio
    MsgBox pv, 64, "Lock status"
    ULabel
End If
End Sub

Private Sub Class_Initialize()
MsgBox "The EventHandler class has been initialized."
End Sub

VBA Code:
' Powerpoint standard module

Public pv
Dim ribbonUI As IRibbonUI, cPPTObject As New EventClass, TrapFlag As Boolean

Sub ribbonLoaded(ribbon As IRibbonUI)
Set ribbonUI = ribbon
End Sub

Sub ULabel()
ribbonUI.InvalidateControl ("Login")
End Sub

Sub getLL(control As IRibbonControl, ByRef returnedVal)
returnedVal = CStr(pv)
End Sub

Sub TrapEvents()
MsgBox "Trapping event..."
If TrapFlag = True Then
    MsgBox "the EventHandler is already active.", _
    vbInformation + vbOKOnly, "PP Event Handler"
    Exit Sub
End If
Set cPPTObject.PPTEvent = Application
TrapFlag = True
End Sub

Sub ReleaseTrap()
If TrapFlag = True Then
    Set cPPTObject.PPTEvent = Nothing
    Set cPPTObject = Nothing
    TrapFlag = False
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top