Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If you pass the password to this line:
ActiveSheet.Unprotect It may work: ActiveSheet.Unprotect password:=mystr1 Tim Whitley wrote: 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 -- Dave Peterson |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Problem solved. Thanks so much for your help...an elegant and simple solution.
"Dave Peterson" wrote: If you pass the password to this line: ActiveSheet.Unprotect It may work: ActiveSheet.Unprotect password:=mystr1 Tim Whitley wrote: 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 -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Password Protecting/Unprotecting Via Code | Excel Programming | |||
Unprotecting password protected workbook | Excel Discussion (Misc queries) | |||
Macro that password protects a sheet | Excel Discussion (Misc queries) | |||
Unprotecting a Sheet | Excel Programming | |||
Simple password function - unprotecting sheets | Excel Programming |