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