Hi Friends,
I worte a procedure to protect the worksheet. When we clik on command button it asks the password but if I click on cancel button procedure is exiting.
Please help me with this code.
Private Sub CommandButton1_Click()
Dim pword As String
Dim msg As String
Dim ans As Integer
TryAgain:
' Set up error handling if the entered password is wrong then control goes to the BadEntry label.
On Error GoTo BadEntry
'Assigned inputbox function to pword variable
pword = InputBox("Enter the password", "Unlock the source sheet")
'checks for password to unprotect the sheet
If pword = "sadc" Then
Sheets("source").Unprotect pword
Exit Sub
End If
BadEntry:
'Assigned msgbox information to msg variable
msg = "Wrong Password, Try again?"
'Assigned msgbox information to ans variable
ans = MsgBox(msg, vbYesNo, "Information")
If ans = vbNo Then
Exit Sub
End If
'It checks weather user selected yes or no command butoons if the user selected "Yes"
'then the control goes to AryAgrain label.
If ans = vbYes Then GoTo TryAgain
'Then Resume TryAgain
'Exit Sub
End Sub
Thans and Regards
Ramesh
Bookmarks