G
Guest
I attached the following code attached to a Command Button. The purpose is
to ask the user for the unprotect password and if the password is correct, to
unhide cells and unprotect the sheet. My only problem is that this asks the
user for the password twice. I felt it was necessary to add the If, Then,
Else component because otherwise the unprotect command would allow the user
to "debug" if the password was entered incorrectly which would allow them to
see the protect code with the password built in.
I understand why it is asking for the password twice, I just don't know of a
way around it. Also, I am a novice so any help is greatly appreciated.
Using VBA in Excel 2003.
Thanks in advance
'Private Sub CommandButton1_Click()
'must lock VBA project so you can't see the password in it
Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("show$") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required")
If MyStr1 = MyStr2 Then
Rows("33:40").Select
Selection.EntireRow.Hidden = False
ActiveSheet.Unprotect
Else
MsgBox ("Access Denied")
End If
End Sub
to ask the user for the unprotect password and if the password is correct, to
unhide cells and unprotect the sheet. My only problem is that this asks the
user for the password twice. I felt it was necessary to add the If, Then,
Else component because otherwise the unprotect command would allow the user
to "debug" if the password was entered incorrectly which would allow them to
see the protect code with the password built in.
I understand why it is asking for the password twice, I just don't know of a
way around it. Also, I am a novice so any help is greatly appreciated.
Using VBA in Excel 2003.
Thanks in advance
'Private Sub CommandButton1_Click()
'must lock VBA project so you can't see the password in it
Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("show$") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required")
If MyStr1 = MyStr2 Then
Rows("33:40").Select
Selection.EntireRow.Hidden = False
ActiveSheet.Unprotect
Else
MsgBox ("Access Denied")
End If
End Sub