Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro asking for a password twice when unprotecting sheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Macro asking for a password twice when unprotecting sheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Macro asking for a password twice when unprotecting sheet

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Password Protecting/Unprotecting Via Code MWS Excel Programming 3 December 12th 05 03:21 PM
Unprotecting password protected workbook Vnagpal Excel Discussion (Misc queries) 1 December 10th 05 06:33 AM
Macro that password protects a sheet Ryan Excel Discussion (Misc queries) 1 November 10th 05 05:42 PM
Unprotecting a Sheet Scott O'Donnell Excel Programming 2 October 3rd 04 11:26 PM
Simple password function - unprotecting sheets Peter Hill Excel Programming 4 September 24th 03 03:38 AM


All times are GMT +1. The time now is 05:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"