Lock/Unlock problem

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

By using the two macros below, which works fine, I would like to toggle the
lock/unlock
function with one button only instead of the two which I use at present.
Sadly I can't get it to work, any ideas gratefully received.
Jim

Sub UnlockSheet()
On Error Resume Next
With ActiveSheet
.Unprotect
End With
On Error GoTo 0
End Sub

Sub LockSheet()
On Error Resume Next
With ActiveSheet
.Protect
End With
On Error GoTo 0
End Sub
 
Hi Jim,

you can try this
Sub ToggleSheet()
On Error Resume Next
With ActiveSheet
If .ProtectContents = True Then
.Unprotect
Else
.Protect
End If
End With
On Error GoTo 0
End Sub

HTH
Frank
 
Back
Top