请帮助!我一直在遵循有关如何通过登录页面使文档的工作表密码受到保护的教程。我在下面的**行上遇到运行时错误的问题。Sheets(SheetNm)。保护“ 123”Sheets(SheetNm).Visible = xlSheetVisible如果结束我设法通过删除然后重新插入行开头的制表符空间来绕过它一次。但是我不知道为什么这样行得通,而且成功没有重复。有人知道如何解决我收到的错误吗?
Sub CheckUser()
Dim UserRow, SheetCol As Long
Dim SheetNm As String
With Sheet1
.Calculate
If .Range("B9").Value = Empty Then
Debug.Print "Incorrect UserName"
MsgBox "Please enter correct User Name"
Exit Sub
End If
If .Range("B8").Value <> True Then
Debug.Print "Incorrect Password"
MsgBox "Please enter correct password"
Exit Sub
End If
UserRow = .Range("B9").Value 'User Row
For SheetCol = 5 To 14
SheetNm = Cells(2, SheetCol).Value 'Sheet Name
If .Cells(UserRow, SheetCol).Value = "Ð" Then
**Sheets(SheetNm).Protect "123"
Sheets(SheetNm).Visible = xlSheetVisible
End If**
If .Cells(UserRow, SheetCol).Value = "Ï" Then
Sheets(SheetNm).Protect "123"
Sheets(SheetNm).Visible = xlSheetVisible
End If
If .Cells(UserRow, SheetCol).Value = "x" Then Sheets(SheetNm).Visible = xlVeryHidden
Next SheetCol
End With
End Sub
嘿,我正在尝试找出一种通过此代码保护工作表之前检查格式行框的方法。反正有这样做吗?