PDA

View Full Version : Password TextBox in UserForm



marreco
01-11-2012, 02:40 AM
Good morning people!

The following code prevents the common user to change any value in the cells.
But I need the administrator of the spreadsheet has the ability to change the data, I have a UserForm with a TextBox.

How do I adapt the code below and when the administrator of the worksheet, have the need to change the worksheet data. call the UserForm code so that it can do this with password in the TextBox?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim NewValue As Variant, OldValue As Variant
If Target.Count > 1 Then Exit Sub
'Say you want to work with the range A1:F100
If Not Intersect(Target, Range("A1:F1000")) Is Nothing Then
NewValue = Target.Value
Application.EnableEvents = False
Application.Undo
OldValue = Target.Value
If OldValue = "" Then
Target.Value = NewValue
'ElseIf 'Before there was InputBox Then
Target.Value = NewValue
Else: MsgBox "Você não pode alterar o conteudo da celula.", 16, "Células Bloqueadas"
Target.Value = OldValue
End If
Application.EnableEvents = True
End If
End Sub

Kenneth Hobs
01-11-2012, 06:38 AM
In this example, I showed how to use the PasswordChar for a Textbox control. http://www.vbaexpress.com/forum/showthread.php?t=39420

I would recommend that you protect the sheet and add an option for the administrator to unprotect it. You would set the protection back when the file is saved and/or closed. You could use Environ("username") and avoid the password dialog.

marreco
01-11-2012, 03:41 PM
Hi...:(

Thanks for responding.
Unfortunately two people use the same spreadsheet.
The code that prevents the Common User have to change the data ings and discussed that since both use the same worksheet.

It works well when a user tries to change the data, appears an InputBox.
But the InputBox, no secret characters, so I have to use ma TextBox.

I do not know how to adapt the code I have, I would call the UserForm instead of InputBox.

marreco
01-12-2012, 05:49 PM
Hi..

:(

someone has an idea of ​​how to help me?
I would be very grateful Thank you!:

Kenneth Hobs
01-12-2012, 06:18 PM
I explained that you can use the textbox control on a userform to do that with the example link.

marreco
01-13-2012, 03:16 AM
Hi..

Thanks again Kenneth.
But in your example worksheet cells still blocked.

You know me explain why this happened?