Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Protect/ unprotect worksheet cc Excel Discussion (Misc queries) 0 October 19th 07 09:27 PM
How do I unprotect a protected worksheet that has passwrod protect Iain A C T Excel Discussion (Misc queries) 9 September 28th 05 05:38 AM
Protect/Unprotect Worksheet djn Excel Discussion (Misc queries) 1 May 12th 05 11:27 PM
Unprotect and protect.... Wilfrid Excel Programming 1 July 28th 04 03:13 AM
Excel VBA - Problems using Protect/Unprotect a worksheet Gary Richie Excel Programming 2 February 6th 04 03:29 AM


All times are GMT +1. The time now is 06:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"