我試圖創建一個多用戶登錄。我有一個專門用於用戶名和密碼的單元格的歡迎表,以及一個包含用戶名和密碼組合的表單。登錄多個用戶
我得到一個錯誤If wk.Range("B3").Value = ws.Range(i, "A").Value Then
它說「對象定義」的錯誤。
我認爲它是有道理的,只是試圖檢查單元格中的字符串是否通過循環匹配用戶表中的用戶名/密碼。 我不確定是否正確。然後根據您是否以操作員或其他用戶身份登錄,它會影響您看到的表單。
Public CurrentUser As String, CurrentRole As String, LoginUserName As String, LoginPassword As String
Public LoginStatus As Boolean
Sub Login()
'Worksheets("Users").Activate
Dim numberOfUsers, i As Integer
Dim ws, wk As Worksheet
Set ws = ThisWorkbook.Worksheets("Users")
Set wk = ThisWorkbook.Worksheets("Welcome")
numberOfUsers = ws.Range("Users").Rows.Count
LoginStatus = False
For i = 1 To numberOfUsers
If wk.Range("B3").Value = ws.Range(i, "A").Value Then
If wk.Range("B4").Value = ws.Range(i, "B").Value Then
CurrentUser = wk.Range("B3").Value
LoginStatus = True
Else
LoginStatus = False
MsgBox ("Wrong Login Data")
End If
Else
LoginStatus = False
MsgBox ("Wrong Login Data")
Next i`
Select Case CurrentUser
Case "Operator"
Worksheets("Received_Calls").Visible = True
Worksheets("Welcome").Visible = False
Worksheets("Users").Visible = False
Worksheets("Reported_actions").Visible = False
Worksheets("Parameters").Visible = False
Worksheets("Distances").Visible = False
Worksheets("NewCalls").Visible = False
Worksheets("NewActions").Visible = False
Case Else
Worksheets("Received_Calls").Visible = False
Worksheets("Welcome").Visible = False
Worksheets("Users").Visible = False
Worksheets("Reported_actions").Visible = True
Worksheets("Parameters").Visible = False
Worksheets("Distances").Visible = False
Worksheets("NewCalls").Visible = False
Worksheets("NewActions").Visible = False
'need to filter
End Select
End Sub
你不想看錶到工作表,而不是工作簿到工作表?看來你已經有點錯字:。wk.Range( 「B3」)值= ws.Range(I, 「A」)的價值應該是ws.Range( 「B3」)值= ws.Range(我,「A」)。價值 – sous2817
你也可以避開環路通過在用戶工作表的列C串聯您的用戶名和密碼一起使用匹配函數... – sous2817
souldn't'ws.Range(I,「A」 ).Value'是'ws.Range(「A」&i).Value'或'ws.Cells(i,1).Value' –