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.
CodePudding user response:
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
CodePudding user response:
I found the solution. A few too many errors on my behalf.
Here's the working code:
Sub ToggleAspectRatio()
'PURPOSE: Toggle Lock Aspect Ratio Property on/off
Dim ShapeName As String
On Error GoTo err_handler
With ActiveWindow.Selection.ShapeRange
If .LockAspectRatio = True Then
.LockAspectRatio = False
Else
.LockAspectRatio = True
End If
End With
Exit Sub
err_handler:
MsgBox "No object is selected"
Exit Sub
End Sub
Thanks @johnk
