Unprotect via prompt

  • Thread starter Thread starter gavmer
  • Start date Start date
G

gavmer

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!!!!!
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top