如何在Excel中使用userform VBA记住'red x'时的密码 [英] How to make userform in Excel VBA remember password when 'red x' is pressed

查看:210
本文介绍了如何在Excel中使用userform VBA记住'red x'时的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



用户通常必须运行更多次,每次提示输入登录凭据所以我希望userform在用户/密码一直被提供直到工作簿被关闭之前记住。



它正常工作,直到用户按下进程按钮或从关闭按钮关闭用户窗体,但是当他/她用红色 x',用户/通行证在下次运行时消失。



我知道'红色x'可以被禁用,但是如果有另一种方式,我很好奇即使在按下红色x的情况下,也可以记录用户记录吗?



以下是我的代码:

  Private Sub cbCancel_Click()
maplogin.Hide
End Sub

Sub cbProcess_Click()

Dim drivetomap As String
静态用户As String
静态传递As String

pcname = ActiveCell.Value
user = Me.txtUser.Value
pass = Me。 txtPass.Value
...


解决方案

你可以重定向X来运行取消按钮代码:

  Private Sub UserForm_QueryClose(Cancel As Integer,CloseMode As Integer)
如果C lostMode = vbFormControlMenu然后
取消= True
cbCancel_Click
如果
End Sub


I have a userform that calls a function with username/password prompt.

The user usually has to run it more times and each time is prompted for the login credentials so I want the userform to remember the user/password once it has been given until the workbook has been closed.

It is working fine until the user presses the 'process' button or closes the userform from the 'close' button, but when he/she closes it with the 'red x', the user/pass disappears on the next run.

I know that the 'red x' can be disabled, but I am curious if there is another way to make the userform remember even when the 'red x' is pressed?

Here is my code so far:

Private Sub cbCancel_Click()
maplogin.Hide
End Sub

Sub cbProcess_Click()

Dim drivetomap As String
Static user As String
Static pass As String

pcname = ActiveCell.Value
user = Me.txtUser.Value
pass = Me.txtPass.Value
...

解决方案

You can redirect the X to run the cancel button code instead:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = vbFormControlMenu Then
        Cancel = True
        cbCancel_Click
    End If
End Sub

这篇关于如何在Excel中使用userform VBA记住'red x'时的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆