Using an Input Box to Unprotect a Worksheet

P

Pablo

I have what is probably an easy question but I cannot seem to come up with a
solution. I have a worksheet that I am protecting various columns with a
password. On the worksheet I have a button with a macro attached to it. I
would like to have an InputBox appear requesting a password that will
unprotect the worksheet when the button is clicked.

All help is greatly appreciated.

Thanks.
 
M

Mike H

Pablo,

This utilises an inputbox so there is no password mask and it can be read by
anyone looking. You can have a masked input box but that is more complicated
or you can use a userform to look like an input box and have a password mask
in that

Sub Button1_Click()
response = InputBox("Enter Password")
On Error GoTo GetMeOut
ActiveSheet.Unprotect Password:=response
'your code



Exit Sub
GetMeOut:
MsgBox "Incorrect password supplied"
End Sub

Mike
 
P

Pablo

Thank you very much.

Mike H said:
Pablo,

This utilises an inputbox so there is no password mask and it can be read by
anyone looking. You can have a masked input box but that is more complicated
or you can use a userform to look like an input box and have a password mask
in that

Sub Button1_Click()
response = InputBox("Enter Password")
On Error GoTo GetMeOut
ActiveSheet.Unprotect Password:=response
'your code



Exit Sub
GetMeOut:
MsgBox "Incorrect password supplied"
End Sub

Mike
 

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