Search code examples
vbaexcelpassword-protectionexcel-2016

VBA Protected Sheet Becomes Unprotected by User Under Review Tab


I am having an issue. Whenever I protect a sheet using a VBA Code as followed:

Sheets("SheetName").Protect Password:= pwd

The sheet does become protected, HOWEVER, the sheet can manually be unprotected by the users when they go under the 'Review' Tab and click 'UnProtect'. No password is required even though there is one there. Please help!


Solution

  • I think your syntax is incorrect.

    If pwd is the value of your password then you have to put it between " like this:

    Sheets("SheetName").Protect Password:="pwd"
    

    If pwd is the name of your variable that contains the password please make sure it's not empty and that you do not have a blank character after the Password:=.

    It should look like this:

    Dim pwd As String
    pwd = "pass"
    
    Sheets("SheetName").Protect Password:=pwd