Share via

MACRO: toggle Lock / un Lock worksheet

Anonymous
2012-10-19T04:01:51+00:00

Sorry,  Mistake:    WORKBOOK,  not worksheet in title,  just need to modify 1 line in my example.

  (am only trying to have a 1 button - 1 click for:  LOCK WINDOWS checkbox / UNLOCK workBOOK :)

thanks.  - must be a 1 liner test for workBook state = locked   ???

hi,  am just trying to save a step each time want to modify something on a worksheet rather keep locked.  is there a way to test the its state for being locked?  (not good at vba,  will need a working example,  thanks)

macro got:

Sub Macro2()

'

    ActiveWorkbook.Unprotect

    ActiveWorkbook.Protect Structure:=True, Windows:=True

End Sub

to something like:

IF workbook is protected, then    ' < - FIX THIS LINE

    ActiveWorkbook.Unprotect

Else

    ActiveWorkbook.Protect Structure:=True, Windows:=True

End IF

==========    ANSWER:  (if this was the only post on this subject..)

'simple toggle (for items desired), in a single click / round trip for protect - unprotect worksheet.

'ie:  no more having to check the windows box.  one less thing to worry about.

Sub protect()   'goal: simple 1 click when changing protect state: skip windows check box

If ActiveWorkbook.ProtectWindows Then    'answer

    ActiveWorkbook.Unprotect

    Else

    ActiveWorkbook.protect Structure:=True, Windows:=True

    End If

End Sub

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments