#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Password

Can you help please?
To password protect a worksheet I am using the following code:

Private Sub Worksheet_Activate()
'password protect your VBA project
Dim strPassword As String
On Error Resume Next
Const Password = "dafydd"

Me.Protect Password:=Password
Me.Columns.Hidden = True

strPassword = InputBox("Enter password to view this sheet")

If strPassword = "" Then
Me.Previous.Select
Exit Sub
ElseIf strPassword < Password Then
MsgBox "Password Incorrect", , "Wrong password"
Me.Previous.Select
Exit Sub
Else
Me.Unprotect Password:=Password
Me.Columns.Hidden = False
End If

On Error GoTo 0
End Sub

Private Sub Worksheet_Deactivate()
On Error Resume Next
Me.Columns.Hidden = True
On Error GoTo 0
End Sub

Is there a way I can adjust the code so that the password doesn't actually
show when it is typed?

  #2   Report Post  
Posted to microsoft.public.excel.misc
Udo Udo is offline
external usenet poster
 
Posts: 48
Default Password

On 27 Nov., 12:13, dafydd wrote:
Can you help please?
To password protect a worksheet I am using the following code:

Private Sub Worksheet_Activate()
'password protect your VBA project
Dim strPassword As String
On Error Resume Next
Const Password = "dafydd"

Me.Protect Password:=Password
Me.Columns.Hidden = True

strPassword = InputBox("Enter password to view this sheet")

If strPassword = "" Then
Me.Previous.Select
Exit Sub
ElseIf strPassword < Password Then
MsgBox "Password Incorrect", , "Wrong password"
Me.Previous.Select
Exit Sub
Else
Me.Unprotect Password:=Password
Me.Columns.Hidden = False
End If

On Error GoTo 0
End Sub

Private Sub Worksheet_Deactivate()
On Error Resume Next
Me.Columns.Hidden = True
On Error GoTo 0
End Sub

Is there a way I can adjust the code so that the password doesn't actually
show when it is typed?


Insert on top the line
Application.Screenupdating = False

and at the end insert
Application.screenupdating = True

Good luck
Udo
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Password

Interesting, simple solution - but probably doesn't want to put that
instruction right at the top - right after the Me.Columns.Hidden statement
might be a better place.

I was going to suggest using a UserForm - since the text boxes in a form can
be given a 'password character' as one of their properties - all typed into
the text box are displayed as that character. Basically the
Worksheet_Activate() process would just pull up the userform, as
UserForm1.Show
and pretty much the code dafydd has there now would be in the userform's
code segments, using ActiveSheet instead of Me (since Me would then refer to
the form and not the sheet).

But if the Application.ScreenUpdating =True/False statement do the job for
him, it's much easier to implement at this point.

"Udo" wrote:

On 27 Nov., 12:13, dafydd wrote:
Can you help please?
To password protect a worksheet I am using the following code:

Private Sub Worksheet_Activate()
'password protect your VBA project
Dim strPassword As String
On Error Resume Next
Const Password = "dafydd"

Me.Protect Password:=Password
Me.Columns.Hidden = True

strPassword = InputBox("Enter password to view this sheet")

If strPassword = "" Then
Me.Previous.Select
Exit Sub
ElseIf strPassword < Password Then
MsgBox "Password Incorrect", , "Wrong password"
Me.Previous.Select
Exit Sub
Else
Me.Unprotect Password:=Password
Me.Columns.Hidden = False
End If

On Error GoTo 0
End Sub

Private Sub Worksheet_Deactivate()
On Error Resume Next
Me.Columns.Hidden = True
On Error GoTo 0
End Sub

Is there a way I can adjust the code so that the password doesn't actually
show when it is typed?


Insert on top the line
Application.Screenupdating = False

and at the end insert
Application.screenupdating = True

Good luck
Udo

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Password

Hi,

I'm a bit sceptical about applicatin.screenupdating working and input boxes
don't have a password character property but there is a workaround:

http://www.xcelfiles.com/API_09.html

I've used this and it works but I wouldn't bother again it's far to much
hassle when a userform does it using inbuilt functionality.

Mike

"dafydd" wrote:

Can you help please?
To password protect a worksheet I am using the following code:

Private Sub Worksheet_Activate()
'password protect your VBA project
Dim strPassword As String
On Error Resume Next
Const Password = "dafydd"

Me.Protect Password:=Password
Me.Columns.Hidden = True

strPassword = InputBox("Enter password to view this sheet")

If strPassword = "" Then
Me.Previous.Select
Exit Sub
ElseIf strPassword < Password Then
MsgBox "Password Incorrect", , "Wrong password"
Me.Previous.Select
Exit Sub
Else
Me.Unprotect Password:=Password
Me.Columns.Hidden = False
End If

On Error GoTo 0
End Sub

Private Sub Worksheet_Deactivate()
On Error Resume Next
Me.Columns.Hidden = True
On Error GoTo 0
End Sub

Is there a way I can adjust the code so that the password doesn't actually
show when it is typed?

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 Jeff Excel Discussion (Misc queries) 1 December 21st 06 11:29 PM
password flow23 Excel Discussion (Misc queries) 0 March 31st 06 11:02 AM
How to see macro code of a password protected macro without a password? Dmitry Kopnichev Excel Worksheet Functions 5 October 27th 05 09:57 AM
how to automate opening a password protected excel file? e.g. a .xls that has a password set in the security tab. Daniel Excel Worksheet Functions 0 June 23rd 05 11:56 PM
bypass password when update linking of password protected file Yan Excel Discussion (Misc queries) 1 February 7th 05 11:29 PM


All times are GMT +1. The time now is 02:09 PM.

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

About Us

"It's about Microsoft Excel"