Private Sub ComboBox1_Change()
End Sub
Private Sub CommandButton1_Click()
If ComboBox1.Text = "" Or TextBox1.Text = "" Or TextBox2 = "" Then
MsgBox "请填写齐全!", 1 + 64, "系统登录"
TextBox1.SetFocus
Else
If 取指定用户密码(ComboBox1) = TextBox1.Text Then
Unload Me
MsgBox ComboBox1.Text & "你好!欢迎你进入本系统。", 1 + 64, "欢迎界面"
Sheets("用户及密码").Range("d2") = ComboBox1.Text
Application.Visible = True
ActiveWorkbook.Unprotect PASSWORD:="yubiao"
Sheets("产品进出账").Visible = True
Sheets("产品进出账").Activate
ActiveWorkbook.Protect PASSWORD:="yubiao"
Else
MsgBox "对不起登录密码错误,请重新输入!"
End If
End If
End Sub
Private Sub CommandButton2_Click()
Unload Me
Application.Visible = True
ActiveWorkbook.Close savechanges:=False
End Sub
Private Sub CommandButton3_Click()
ComboBox1 = ""
TextBox1 = ""
TextBox2 = ""
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub TextBox2_Change()
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox2.Value <> Label4.Caption Then
MsgBox "验证码输入错误,请重新录入"
Cancel = True
End If
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
ComboBox1.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
Private Sub Label4_Click()
生成验证码
End Sub
Sub 生成验证码()
验证码 = Int(Rnd() * 9000 + 1000)
Label4.Caption = 验证码
End Sub
Option Explicit
Private Sub Workbook_Open()
Application.Visible = False
系统登录.Show
ActiveWorkbook.Unprotect "yubiao"
Sheets("用户及密码").Visible = False
If Sheets("用户及密码").Range("d2") = "余彪" Then
ActiveSheet.Unprotect "yubiao"
Else
ActiveSheet.Protect "yubiao"
End If
ActiveWorkbook.Protect "yubiao"
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Sheets("用户及密码").Range("d2") = "余彪" Then
ActiveWorkbook.Close savechanges:=True
Else
ActiveWorkbook.Close savechanges:=False
End If
'Application.Quit
End Sub
Function 取指定用户密码(X As Object)
Dim Mrow As Integer
Mrow = Sheets("用户及密码").Cells.Find(X.Text).Row
取指定用户密码 = Sheets("用户及密码").Cells(Mrow, 2)
End Function
|