Private Sub cmdLogin_Click()
On Error GoTo ErrorHandler
Dim RowNo As Long
Dim Id As String
Dim pw As String
Dim ws As Worksheets
Application.ScreenUpdating = False
Set ws = Worksheets("User&Pass")
Id = LCase(Me.txtLogin)
RowNo = Application.WorksheetFunction.Match(Id, ws.range("A2:A999"), 0)
CleanExit:
Set ws = Nothing ' free memory
Application.ScreenUpdating = True ' turn on the screen updating
Exit Sub
ErrorHandler:
MsgBox "Unable to match ID, enter valid ID.", vbOKOnly
GoTo CleanExit
End Sub
我有一个excel用户表单我一直在努力,现在我需要它通过登录屏幕看起来更专业。我已经开始使用上面的代码,但是我已经陷入了死胡同。Excel vba用户名/密码查找
如何设置我的目的是说如果密码匹配,然后加载工作簿或取消隐藏工作簿并继续。用户名和密码位于名为“用户&通行证”的表单中 目的是从a-user/b-pw的列分别读取,如果它是成功的,我将隐藏该表以便他们不能看到其他用户的信息
与我上面开始我只需要它说,如果它匹配usercolumn那么相应的PW隔壁它继续别人去我的ErrorHandler
我可以做格式化有关隐藏和取消隐藏表等只需要阅读帮助用户名和密码
非常感谢 Z
编辑尝试一个;
Private Sub cmdLogin_Click()
On Error GoTo ErrorHandler
Dim RowNo As Long
Dim Id As String
Dim pw As String
Dim ws As Worksheets
Application.ScreenUpdating = False
Set ws = Worksheets("User&Pass")
Id = LCase(Me.txtLogin)
RowNo = Application.WorksheetFunction.Match(Id, ws.range("A2:A999"), 0)
RowNo = RowNo + 1
pw = ws.range("B" & RowNo)
If pw = Me.txtLogin Then
'continue
txt1.Value = "yes"
Else
GoTo ErrorHandler
End If
CleanExit:
Set ws = Nothing ' free memory
Application.ScreenUpdating = True ' turn on the screen updating
Exit Sub
ErrorHandler:
MsgBox "Unable to match ID, enter valid ID.", vbOKOnly
GoTo CleanExit
End Sub
@siddarthRout
Private Sub cmdLogin_Click()
Dim RowNo As Long
Dim Id As String, pw As String
Dim ws As Worksheet
Dim aCell As range
On Error GoTo ErrorHandler
Application.ScreenUpdating = True
Set ws = Worksheets("Details")
Id = LCase(Me.txtLogin)
Set aCell = ws.Columns(1).Find(What:=Id, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
'~~> If match found
If Not aCell Is Nothing Then
RowNo = aCell.Row
'~~> Rest of your code. For example if the password is
'~~> Stored in Col B then
Debug.Print aCell.Offset(, 1)
Unload Me
FrmMenu.Show
'~~> You can then use the above aCell.Offset(, 1) to
'~~> match the password which the user entered
Else '<~~ If not found
MsgBox "Unable to match ID, enter valid ID.", vbOKOnly
End If
CleanExit:
Set ws = Nothing
Application.ScreenUpdating = True
Exit Sub
ErrorHandler:
MsgBox Err.Description
Resume CleanExit
End Sub
快速提示:这是否意味着是一个非常安全的密码?特别是以这种方式完成的Excel对此非常不利。 – Gaffi 2012-03-15 13:57:11
如果有一种方法使它看起来熟悉用户名和密码,并确保以不同的方式做到这一点我是所有人的耳朵,我的代码是我尝试过的一个例子,只是尝试调整你放入的东西,但没有运气 – Zenaphor 2012-03-15 13:59:01
为什么不只是有一个授权用户的列表,然后验证登录的Windows用户名对此?这样就不需要用户名和密码 – SWa 2012-03-15 14:01:02