ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Unprotect via prompt (https://www.excelbanter.com/excel-programming/311274-unprotect-via-prompt.html)

gavmer[_81_]

Unprotect via prompt
 

Hi Rog,

Thanks for the reply but i should pprovide more info. The buttons ar
actually on a separate sheet. Does this affect the manual process o
protecting/unprotecting sheets??

Cheers!!!!!

--
gavme
-----------------------------------------------------------------------
gavmer's Profile: http://www.excelforum.com/member.php...nfo&userid=666
View this thread: http://www.excelforum.com/showthread.php?threadid=26268


Dave Peterson[_3_]

Unprotect via prompt
 
After some private exchanges:

Option Explicit

Private Sub CommandButton1_Click()
'unprotect

Application.ScreenUpdating = False

If Worksheets("sheet2").ProtectContents _
Or Worksheets("sheet2").ProtectDrawingObjects _
Or Worksheets("sheet2").ProtectScenarios Then
Worksheets("sheet2").Activate
On Error Resume Next
Application.Dialogs(xlDialogProtectDocument).Show
On Error GoTo 0
Else
MsgBox "already unprotected"
End If

If Worksheets("sheet2").ProtectContents _
Or Worksheets("sheet2").ProtectDrawingObjects _
Or Worksheets("sheet2").ProtectScenarios Then
MsgBox "Please provide the correct password when prompted " & _
"when you try this again."
End If

Me.Activate

Application.ScreenUpdating = True

End Sub

Private Sub CommandButton2_Click()
'protect

Application.ScreenUpdating = False

If Worksheets("sheet2").ProtectContents _
Or Worksheets("sheet2").ProtectDrawingObjects _
Or Worksheets("sheet2").ProtectScenarios Then
MsgBox "already protected"
Else
Worksheets("sheet2").Activate
Application.Dialogs(xlDialogProtectDocument).Show
End If

If Worksheets("sheet2").ProtectContents _
Or Worksheets("sheet2").ProtectDrawingObjects _
Or Worksheets("sheet2").ProtectScenarios Then
Else
MsgBox "The worksheet is not protected"
End If

Me.Activate

Application.ScreenUpdating = True

End Sub

gavmer wrote:

Hi Rog,

Thanks for the reply but i should pprovide more info. The buttons are
actually on a separate sheet. Does this affect the manual process of
protecting/unprotecting sheets??

Cheers!!!!!!

--
gavmer
------------------------------------------------------------------------
gavmer's Profile: http://www.excelforum.com/member.php...fo&userid=6662
View this thread: http://www.excelforum.com/showthread...hreadid=262682


--

Dave Peterson



All times are GMT +1. The time now is 12:38 AM.

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