我一直在拖網堆棧溢出的一些支持和協助,並找到了下面的代碼。我已將其更改爲我的規格。我想要VBA代碼做的事情是,當我點擊登錄時,我希望它搜索名爲「訪問列表」的工作表並確認用戶是否在工作表中找到。如果找到用戶,則顯示錶單(拉式打印,推式打印,USB,閾值和站點觸點)。一旦它完成了這項任務,我就會喜歡它隱藏「歡迎」頁面。Excel VBA登錄並顯示一組頁數
我已經能夠編碼這部分,但我正在努力的部分是,如果用戶離開密碼字段的用戶名&空白,他們只需點擊登錄。我看到的消息是
對象不支持此屬性或方法
是否有人可以幫助我嗎?
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
If Len(Trim(txtlogin)) = 0 Then
txtlogin.SetFocus
MsgBox "Username cannot be empty"
Exit Sub
End If
If Len(Trim(txtpassword)) = 0 Then
txtpassword.SetFocus
MsgBox "Password cannot be empty"
Exit Sub
End If
Application.ScreenUpdating = False
Set ws = Worksheets("Access List")
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
If Me.txtpassword = aCell.Offset(, 1) Then
Else
Sheets("Home").Visible = xlSheetHidden
Sheets("Pull Print").Visible = True
Sheets("Push Print").Visible = True
Sheets("USB").Visible = True
Sheets("Thresholds").Visible = True
Sheets("Site Contacts").Visible = True
Sheets("Access List").Visible = xlSheetHidden
MsgBox "Unable to match UserID or PasswordID, Please try again", vbOKOnly
End If
Else '<~~ If not found
MsgBox "Unable to match UserID or PasswordID, Please try again", vbOKOnly
End If
CleanExit:
Set ws = Nothing
Application.ScreenUpdating = True
Exit Sub
ErrorHandler:
MsgBox Err.Description
Resume CleanExit
End Sub
我現在已經改變了我的代碼,以反映這一點,當我點擊登錄,它仍然沒有取消隱藏 – 2014-09-25 08:36:03