I am new to VBA.
I have a worksheet that is protected/locked with a password.
I have a CommandButton that, when clicked loads a UserForm that is used to enter records into the worksheet.
I want it in such a way that when the CommandButton is clicked, it will prompt the user to enter the unprotect password (used to protect/lock the worksheet), before the UserForm loads.
If the user enters the correct unprotect password, then the UserForm loads. If the user enters the incorrect unprotect password, a MsgBox displays and the UserForm will not load.
The problem is when the CommandButton is clicked, the user will be prompted to enter the unprotect password (Excel's Built-In Unprotect dialog), if the user clicks the "Cancel" button, the UserForm still loads. This is not what i want. What i want is: If the "Cancel" button is clicked, the MsgBox displays, and the UserForm does NOT load.
Below is my code for the CommandButton:
Private Sub CommandButton1_Click()
On Error Resume Next
ActiveSheet.Unprotect
If Err <> 0 Then
MsgBox:
MsgBox "Incorrect Password. Unlock Failed!"
Else
UserForm3.Show
End If
End Sub