核心代码:
' 窗口事件
Private Sub CommandButton1_Click() ' 登录
If ComboBox2.Text = "" Or TextBox1.Text = "" Then
MsgBox "请输入账户或密码", 1 + 64, "系统登录"
Else
If 特定用户密码登录(ComboBox2) = TextBox1.Text Then
Unload Me
MsgBox ComboBox2.Text & "你好!欢迎你进入本系统", 1 + 64, "欢迎词"
Application.Visible = True
Else
MsgBox "登录密码错误,请重新输入"
End If
End If
End Sub
Private Sub CommandButton2_Click() ' 退出
Unload Me
Application.Visible = True
ActiveWorkbook.Close
End Sub
Private Sub UserForm_Initialize() ' 窗口初始化
Dim X As Integer, Y As Integer
X = Sheets("用户及密码").Range("A65536").End(xlUp).Row
For Y = 2 To X
ComboBox2.AddItem Sheets("用户及密码").Cells(Y, 1)
Next Y
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) ' 设置不能通过关闭符号退出,仅能通过退出按钮退出
If CloseMode = 0 Then Cancel = 1
End Sub
VBA实现窗口登录
最新推荐文章于 2024-08-04 10:35:13 发布
核心代码:' 窗口事件Private Sub CommandButton1_Click() ' 登录If ComboBox2.Text = "" Or TextBox1.Text = "" ThenMsgBox "请输入账户或密码", 1 + 64, "系统登录"ElseIf 特定用户密码登录(ComboBox2) = TextBox1.Text ThenUnload MeMsgBox ComboBox2.Text & "你好!欢迎你进入本系统", 1 + 64, "欢迎词.
摘要由CSDN通过智能技术生成