ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   protect/unprotect worksheet (https://www.excelbanter.com/excel-programming/339632-protect-unprotect-worksheet.html)

ALEX

protect/unprotect worksheet
 
I'm trying to use a button to protect/unprotect a sheet. But, I'm not sure
what I should use in the If statement to identify whether the sheet is
protected or not.
Private Sub cmdProtect_Click()
With ActiveSheet
If ActiveSheet.ProtectionMode Then ' not working, it's always True
.Unprotect Password:="password"
cmdProtect.BackColor = &HFFFF00
cmdProtect.Caption = "UnProtected"
Else
.Protect Password:="password", _
Contents:=True, UserInterfaceOnly:=True
cmdProtect.BackColor = &HFF&
cmdProtect.Caption = "Protected"
End If
End With
End Sub

Can anybody help?

Thanks

Jim Thomlinson[_4_]

protect/unprotect worksheet
 
ProtectContents is probably what you are looking for.

if activesheet.protectcontents then
--
HTH...

Jim Thomlinson


"Alex" wrote:

I'm trying to use a button to protect/unprotect a sheet. But, I'm not sure
what I should use in the If statement to identify whether the sheet is
protected or not.
Private Sub cmdProtect_Click()
With ActiveSheet
If ActiveSheet.ProtectionMode Then ' not working, it's always True
.Unprotect Password:="password"
cmdProtect.BackColor = &HFFFF00
cmdProtect.Caption = "UnProtected"
Else
.Protect Password:="password", _
Contents:=True, UserInterfaceOnly:=True
cmdProtect.BackColor = &HFF&
cmdProtect.Caption = "Protected"
End If
End With
End Sub

Can anybody help?

Thanks


ALEX

protect/unprotect worksheet
 
Thank you very much, Jim.

"Jim Thomlinson" wrote:

ProtectContents is probably what you are looking for.

if activesheet.protectcontents then
--
HTH...

Jim Thomlinson


"Alex" wrote:

I'm trying to use a button to protect/unprotect a sheet. But, I'm not sure
what I should use in the If statement to identify whether the sheet is
protected or not.
Private Sub cmdProtect_Click()
With ActiveSheet
If ActiveSheet.ProtectionMode Then ' not working, it's always True
.Unprotect Password:="password"
cmdProtect.BackColor = &HFFFF00
cmdProtect.Caption = "UnProtected"
Else
.Protect Password:="password", _
Contents:=True, UserInterfaceOnly:=True
cmdProtect.BackColor = &HFF&
cmdProtect.Caption = "Protected"
End If
End With
End Sub

Can anybody help?

Thanks



All times are GMT +1. The time now is 12:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com