Unprotecting worksheets only if you have the password

G

Guest

Hi,

I have a macro button that unprotects each worksheet in my workbook. But I
want the user only to have the ability to unprotect each worksheet after a
code is entered. The problem is that if the user chooses "Cancel" or the "X"
button to close the dialogue box, the worksheets proceed to unprotect. I've
taken care of the event that a user enters in an incorrect amount. How do I
prevent the user to unprotect each worksheet if they don't have the correct
password?

Here is my code:

Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
ActiveSheet.Unprotect
On Error GoTo Finish
For Each ws In ThisWorkbook.Worksheets
ws.Unprotect Password:="1111"
Next ws
Finish:
Application.ScreenUpdating = True
End Sub

Thanks in advance,
 
G

Guest

Hi Mike,

How can I have VBA just provide one dialoque box asking the user to provide
a password without Excel cycling through each worksheet to unprotect by
calling up the same dialogue box....

Thanks,
 
M

Mike Fogleman

Provide an InputBox to the user and compare that string to the actual pwd
string. If it matches then use it to unprotect the sheets, if no match then
show a MessageBox that the pwd was wrong and Exit Sub.

Mike F
 

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

Top