在 VBA 密码框上加密密码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26082965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 04:41:11  来源:igfitidea点击:

Encrypt password on VBA password box

excelvbaencryption

提问by Alan Treanor

I have a couple of userforms for my excel spreadsheet and I need to setup an admin panel for certain tasks that I don't want most people to access.

我的 excel 电子表格有几个用户表单,我需要为某些我不希望大多数人访问的任务设置一个管理面板。

The problem I have is that I can setup a simple password protection form however the text is always visible. I want to try and encrypt it so if anyone is looking over my should or one of the other admins shoulders then they cannot see the password.

我的问题是我可以设置一个简单的密码保护表单,但文本始终可见。我想尝试加密它,所以如果有人在查看我的应该或其他管理员之一的肩膀,那么他们就看不到密码。

Is there anyway to have the text appear as ****or something similar?

无论如何让文本显示为****或类似的东西?

Thanks Al

谢谢艾尔

Private Sub CommandButton1_Click()
Dim MyValue As Variant
MyValue = InputBox("Enter Password")
     If MyValue = "lemonade" Then 'lemonade being the password
     Application.Visible = True
     Else
    MsgBox ("Password Incorrect")
End If
End Sub

Edit - I have amended it to follow your suggestion as I had it to bring up an input box instead of creating my own userform.

编辑 - 我已经修改它以遵循您的建议,因为我让它显示了一个输入框,而不是创建我自己的用户表单。

If Pword2.Value = "lemonade" Then
AddPick1.Hide
Report1.Hide
Unload Me
Admin1.Show vbModal
Else
MsgBox ("Password Incorrect")
End If

When the password is incorrect it gives the incorrect password error however when it is correct it gives me the following error (Must close of hide topmost modal form first) However I have it to set to hide all other forms before loading the Admin1 form?

当密码不正确时,它会给出不正确的密码错误,但是当它正确时,它会给我以下错误(必须先关闭隐藏最上面的模式表单)但是我在加载 Admin1 表单之前将其设置为隐藏所有其他表单?

回答by barryleajo

In the TextBox properties there is a property called PasswordChar. Enter your preferred 'hidden' character in here.

在 TextBox 属性中有一个名为 PasswordChar 的属性。在此处输入您喜欢的“隐藏”字符。

You can also add a button to your form to reveal the password if you wish using the Mouse-Up and Mouse _Down events. MouseDown would look like the following on a textbox called TextBox1 and using a button called CommandButton1:

如果您希望使用 Mouse-Up 和 Mouse _Down 事件,您还可以在表单中添加一个按钮来显示密码。在名为 TextBox1 的文本框和使用名为 CommandButton1 的按钮上,MouseDown 将如下所示:

Private Sub CommandButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    TextBox1.PasswordChar = vbNullChar
End Sub

I'll leave you to code the Mouse_Up event.

我会让你编写 Mouse_Up 事件的代码。

This linkwill give you the usage but you will find plenty of examples with a Google search.

此链接将为您提供用法,但您会通过 Google 搜索找到大量示例。