excel - 用户的用户表单登录 - 错误:从工作簿问题中选择
问题描述
我已经更改了一些代码,现在当我尝试以普通用户身份登录时,它给了我以下错误:“对象'_Worksheet的方法选择”我尝试再次更改代码,但仍然是相同的错误。使用管理员用户,一切正常。我用谷歌搜索可能是因为床单在 xlVeryHidden 但在我拥有它之前它工作得很好......
Private Sub btnEntrar_Click()
'Declare the variables
Dim AddData As Range, Current As Range
Dim user As Variant, Code As Variant
Dim PName As Variant, AName As Variant, UName As Variant
Dim ws As Worksheet, ws2 As Worksheet, ws3 As Worksheet, ws4 As Worksheet, ws5 As Worksheet
Dim result As Integer
Dim TitleStr As String
Dim msg As VbMsgBoxResult
'Set the pages variables
Set ws = Worksheets("Ingreso")
Set ws2 = Worksheets("Ingresos - Usuarios")
Set ws3 = Worksheets("Supervisores")
Set ws4 = Worksheets("LookupList")
Set ws5 = Worksheets("Registros")
'Variables
user = Me.txtUser.Value
Code = Me.txtPass.Value
TitleStr = "Password check"
result = 0
Set Current = ws.Range("M3")
'Error handler
On Error GoTo errHandler:
'Destination location for login storage
Set AddData = ws2.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
'Check the login and passcode for the Administrator
If user <> "" And Not IsNumeric(user) And Code <> "" Then
For Each AName In ws.Range("R4:R6")
'If AName = Code Then 'Use this for passcode text
If AName = Code And AName.Offset(0, -1) = user Then ' Puede usar texto Y números
MsgBox "Inicio como Administrador de: " & user
'record user login
AddData.Value = user
AddData.Offset(0, 1).Value = Now
'Add usernmae to the worksheet
Current.Value = user
'Change variable if the condition is meet
result = 1
'Unload the form
ws.Visible = True 'Cambiar para que lo tome de la tabla de permisos y no manual como ahora, usar el cod de abajo
ws2.Visible = True
ws3.Visible = True
ws4.Visible = True
ws5.Visible = True
ws.Select
Unload Me
Exit Sub
End If
Next AName
End If
'Check user login with loop
If user <> "" And Not IsNumeric(user) And Code <> "" Then
For Each UName In ws.Range("R11:R19")
'If UName = Code Then 'Use this for passcode text
If UName = Code And UName.Offset(0, -1) = user Then ' Puede usar texto Y números
MsgBox "Ingreso satisfactorio para: " & user
'record user login
AddData.Value = user
AddData.Offset(0, 1).Value = Now
'Add usernmae to the worksheet
Current.Value = user
Set PName = Hoja2.Range("E:E").Find(What:=user, LookIn:=xlValues)
'unhide worksheet for user
If PName.Offset(0, 2) = "Ingreso" Then
Set ws = Worksheets(PName.Offset(0, 2).Value)
ws.Visible = True
End If
If PName.Offset(0, 3) = "Ingresos - Usuarios" Then
Set ws2 = Worksheets(PName.Offset(0, 3).Value)
ws2.Visible = True
End If
If PName.Offset(0, 3) = "Supervisores" Then
Set ws3 = Worksheets(PName.Offset(0, 3).Value)
ws3.Visible = True
End If
If PName.Offset(0, 4) = "Registros" Then
Set ws4 = Worksheets(PName.Offset(0, 4).Value)
ws4.Visible = True
End If
If PName.Offset(0, 5) = "LookupList" Then
Set ws5 = Worksheets(PName.Offset(0, 5).Value)
ws5.Visible = True
End If
'show sheet tab if hidden
ActiveWindow.DisplayWorkbookTabs = True
'Change variable if the condition is meet
result = 1
'Unload the form
ws3.Select
Unload Me
'Inicio Automático el Multi
InicioSuperv
Exit Sub
End If
Next UName
End If
解决方案
推荐阅读
- html -
在 FormattedMessage 中用作值(使用 TypeScript ) - javascript - GSAP ScrollTrigger 动画淡入淡出不透明度问题
- mysql - MySql 中的规范化和表
- c# - 'private (string, object)[] s;' 是什么意思?意思/做?
- javascript - 比较数组和过滤器,使用 MongoDB 聚合
- numpy - NumPy 中的 SVG 像素合成操作
- vb.net - Google.Analytics.Data.V1Alpha - 属性“daterange”只读
- csv - AWK:根据两列信息过滤数据
- python - LSTM 上的 Pytorch 修剪会增加模型大小?
- javascript - (Javascript)刷新页面后元素消失