|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
《别怕,VBA其实很简单》教材中的登录窗体案例名称管理如图片附件:
代码和教材中一样,但输入名称管理器储存的用户名user时,程序总是过不去:
Private Sub cmdok_Click()
Application.ScreenUpdating = False
Static i As Integer
Dim a As String, b As String
a = Right(Names("username").RefersTo, Len(Names("username").RefersTo) - 1)
b = Right(Names("userword").RefersTo, Len(Names("userword").RefersTo) - 1)
If CStr(user.Value) = a And _
CStr(password.Value) = b Then
Unload Me
Application.Visible = True
Else
i = i + 1
If i = 3 Then
MsgBox "你无权打开工作簿!", vbExclamation, "提示"
ThisWorkbook.Close savechanges:=False
Else
MsgBox "输入错误,你还有" & (3 - i) & "次输入机会!", vbExclamation, "提示"
user.Value = ""
password.Value = ""
End If
End If
Application.ScreenUpdating = True
End Sub
|
-
名称管理器
|