jonathanwang003
Board Regular
- Joined
- May 9, 2014
- Messages
- 133
Hi guys,
So my workbook is protected. I need a macro which prompts a InputBox saying "Please Enter Password."
If the password is incorrect, it says, "Incorrect password. Please try again." and loops to the first input box.
However... if they hit cancel, I want it to shut off the document. Here's what I have that works for the loop. But then if you get the password wrong... you're screwed.
Sub UnlockWorkbook()
Const PW = "rabbit"
Dim password1 As String
Do
password1 = InputBox("Please Enter Password.")
If password1 <> PW Then
MsgBox "Incorrect password. Please try again."
Else
ActiveWorkbook.Unprotect Password:=password1
MsgBox "Password correct."
End If
Loop While password1 <> PW
End Sub
So my workbook is protected. I need a macro which prompts a InputBox saying "Please Enter Password."
If the password is incorrect, it says, "Incorrect password. Please try again." and loops to the first input box.
However... if they hit cancel, I want it to shut off the document. Here's what I have that works for the loop. But then if you get the password wrong... you're screwed.
Sub UnlockWorkbook()
Const PW = "rabbit"
Dim password1 As String
Do
password1 = InputBox("Please Enter Password.")
If password1 <> PW Then
MsgBox "Incorrect password. Please try again."
Else
ActiveWorkbook.Unprotect Password:=password1
MsgBox "Password correct."
End If
Loop While password1 <> PW
End Sub