• Worksheets – protect/unprotect

    Author
    Topic
    #474436

    (Win XP, O2003 SP3 UK)

    Hi,

    In Excel I have an ‘admin’ menu and a sub menu point ‘Protect/unprotect’ worksheets. With this single menupoint the user to be able to toggle the worksheets of a protected workbook between protected and unprotected states – provided he has sufficient user rights (being on a postive list of users).

    My code right now looks like this – but it doesn’t work as intended.

    For Each c In arrSheets

    ‘Sheets will be protected
    If Worksheets(“Funds”).Protect = True Then
    Worksheets(c).Protect Password:=APP_PWDPROTECT

    Else
    ‘Sheets will be unprotected
    Worksheets(c).Unprotect Password:=APP_PWDPROTECT
    End If

    Next c

    To me it seems that the .Protect/ .unprotect methods don’t have a way of testing whether a worksheet is protected or not, eg. by returning a boolean or the like – it can only set .protect or .unprotect.

    Does anyone know of a clever way to do this kind of toggling (without having to promp the user) :rolleyes:.

    BR

    Viewing 2 reply threads
    Author
    Replies
    • #1265104

      Use:

      Code:
      If Worksheets("Funds").ProtectContents Then

      and reverse the logic, so you unprotect if True.

    • #1265650

      Hi Rory,

      Why use the subset .ProtectContents in comparison to “just” .Protect – after all .Protect includes .ProtectContents as well?? (fwik)
      :confused:

    • #1265788

      Protectcontents is not a sub, it’s a property that tells you whether the sheet is protected. Since that’s what you asked for, that’s what I gave you. 😉

    Viewing 2 reply threads
    Reply To: Worksheets – protect/unprotect

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: