GunnRos86
GunnRos86

Reputation: 33

User can unprotect vba protected sheets without providing the password

I've placed some worksheets protection lines as follows:

Private Sub Workbook_Open()

  Worksheets("Sheet1").Protect password, UserInterfaceOnly:=True
  Worksheets("Sheet1").Protect AllowFiltering:=True

  Worksheets("Sheet2").Protect password, UserInterfaceOnly:=True
  Worksheets("Sheet2").Protect AllowFiltering:=True

  Worksheets("Sheet3").Protect password, UserInterfaceOnly:=True
  Worksheets("Sheet3").Protect AllowFiltering:=True

  Worksheets("Sheet4").Protect password, UserInterfaceOnly:=True
  Worksheets("Sheet4").Protect AllowFiltering:=True

End Sub

However, whenever I click unprotect worksheet from the main menu, excel doesn't ask for any password and simply unprotects the sheet. I am doing something wrong here?

Thanks to all!

Upvotes: 0

Views: 389

Answers (2)

Danhol86
Danhol86

Reputation: 1452

Have you tried protecting sheet in just one line and specifying the password string?

Worksheets("Sheet1").protect Password:="YourPassword", UserInterfaceOnly:=True, AllowFiltering:=True

Upvotes: 0

Dani El
Dani El

Reputation: 173

Worksheets("Sheet1").Protect password, UserInterfaceOnly:=True, AllowFiltering:=True

Do that for each line and it should work well, assuming you did put password sting into the variable password

Upvotes: 1

Related Questions