|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
在学习教程时,第285页的 登录窗体设计,怎么都通不过,请指点一下,看问题出在哪里?
(我是新手。代码个人手打的,没找出什么问题。似乎定义出了问题?)
Private Sub workbook_open()
Application.Visible = False
denglu.Show
End Sub
Private Sub cmdok_Click()
Application.ScreenUpdating = False
Static i As Integer
If CStr(user.Value) = Right(Names("username").RefersTo, Len(Names("username").RefersTo) - 1) _
And CStr(password.Value) = Right(Names("userword").RefersTo, Len(Names("userword").RefersTo) - 1) Then '为什么要-1?
Unload Me
Application.Visible = True
Else
i = i + 1
If i = 3 Then
MsgBox "对不起,超过三次,你无权打开工作簿!", vbInformation, "提示"
ThisWorkbook.Close savechanges:=False
password.Value = ""
Else
MsgBox "输入错误,你还有" & (3 - 1) & "次输入机会", vbExclamation, "提示"
user.Value = ""
password.Value = ""
End If
End If
Application.ScreenUpdating = True
End Sub
Private Sub cmdcancel_Click()
Unload Me
ThisWorkbook.Close savechanges:=False
End Sub
Private Sub userset_Click()
Dim old As String, new1 As String, new2 As String
old = InputBox("请输入原用户名", "提示")
new1 = InputBox("请输入新用户名", "提示")
new2 = InputBox("请再次输入新用户名", "提示")
If old <> "" And new1 <> "" Then
If old = Right(Names("username").RefersTo, Len(Names("username").RefersTo) - 1) And new1 = new2 Then
Names("username").RefersTo = "=" & news1
ThisWorkbook.Save
MsgBox "用户名修改完成,下次登录请用新用户名", vbInformation, "提示"
Else
MsgBox "输入错误,修改没有完成!", vbCritical, "错误"
End If
Else
MsgBox "用户名不能为空", vbCritical, "错误"
End If
End Sub
Private Sub passwordset_Click()
Dim old As String, new1 As String, new2 As String
old = InputBox("请输入原密码", "提示")
new1 = InputBox("请输入密码", "提示")
new2 = InputBox("请再次输入新密码", "提示")
If old <> "" And new1 <> "" Then
If old = Right(Names("userword").RefersTo, Len(Names("userword").RefersTo) - 1) And new1 = new2 Then
Names("userword").RefersTo = "=" & news1
ThisWorkbook.Save
MsgBox "用户名修改完成,下次登录请用新用户名", vbInformation, "提示"
Else
MsgBox "输入错误,修改没有完成!", vbCritical, "错误"
End If
Else
MsgBox "用户名不能为空", vbCritical, "错误"
End If
End Sub
|
|