Search code examples
vbapowerpoint

Toggle Aspect Ratio


I wrote this sub to toggle a shape's Lock Aspect Ratio. It turns locks it but it doesn't unlock it

    Sub ToggleAspectRatio()

With ActiveWindow.Selection.ShapeRange

MsgBox .LockAspectRatio

'On Error GoTo err_handler:
  'Unlock
    If .LockAspectRatio = msoCTrue Then .LockAspectRatio = msoFalse
  'Lock
    If .LockAspectRatio = msoFalse Then .LockAspectRatio = msoCTrue

End With
On Error GoTo 0

Exit Sub

'Error Handler - No Object is Currently Selected
 
 err_handler:
  MsgBox "No object is selected"
  Exit Sub
    
End Sub

Please help me. Thanks in advance.


Solution

  • Your first If statement sets LockAspectRatio to false, your second detects the false and sets it back to true. Instead, use an Else statement:

    If .LockAspectRatio = msoTrue Then
        .LockAspectRatio = msoFalse
    Else
        .LockAspectRatio = msoTrue
    End If