Password Protection

W

WBTKbeezy

I am wondering if it is possible to have a protect macro that has a hardcoded
password so that a user can run the macro and it will protect with the same
macro every time, but the have an unprotect macro that makes people type the
password in. I currently have an unprotect macro, but it when the protected
sheet has a password has a password on, it errors out.

Any suggestions?

Currently I have this
To Protect:
ActiveSheet.Protect Password:="123", DrawingObjects:=True, Contents:=True,
Scenarios:=True

To Unprotect:
ActiveSheet.Unprotect DrawingObjects:=True, Contents:=True, Scenarios:=True

When you run the protect macro and then the unprotect macro it causes an
object or application defined error.

Thanks.
 
N

Norman Jones

Hi W,

Try something like:

'=============>>
Public Sub Tester()
Dim PWORD As String

PWORD = InputBox(Prompt:="Please type the password")

ActiveSheet.Unprotect Password:=PWORD, _
DrawingObjects:=True, _
Contents:=True, _
Scenarios:=True
End Sub
'<<=============
 
W

WBTKbeezy

I have found that if I change the Unprotect Macro to simply read:
ActiveSheet.Unprotect

It works just fine. ( I don't know if I can "un-post" this message, so
apologies if I wasted anyone's time.)
 
K

Kagan Clearwater

Don't forget to put

ActiveSheet.Unprotect Password:="123"...

You need the same password to unprotect.
 
N

Norman Jones

Hi W,

Please replace my suggested code with the following version:

'=============>>
Public Sub Tester()
Dim PWORD As String

PWORD = InputBox(Prompt:="Please type the password")

On Error Resume Next
ActiveSheet.Unprotect Password:=PWORD

If Err.Number <> 0 Then
MsgBox "The password was not recognised"
End If
On Error GoTo 0
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

Similar Threads


Top