我正在创建一个将分发给我的同事的 excel 应用程序。基于权限我需要禁用对某些工作表和功能的访问。我已经能够保护和隐藏工作表,但精明的用户能够在内部或外部迭代隐藏的工作表以公开数据。我需要阻止它。
这是过程:
当工作簿打开对远程数据库的查询时,会返回一组用户权限。然后将这些权限打印到名为“PERMISSIONS”的工作表中。
下面的代码通过传入列名迭代工作表权限以查找特定设置。
CheckPerm "Timesheet"
Public Function CheckPerm(nPermColTarget As String) As Boolean
Dim Counter As Integer
Dim x As Integer
Dim y As Integer
Counter = 3
Do Until Sheet7.Cells(Counter, 1).Value = Associate_Name
Counter = Counter + 1
Loop
y = Counter
Counter = 2
Do Until Sheet7.Cells(2, Counter).Value = nPermColTarget
Counter = Counter + 1
Loop
x = Counter
If Sheet7.Cells(y, x).Value = "ON" Then
CheckPerm = True
GrntDenySheetAccess nPermColTarget, y, x, CheckPerm
Else
' "OFF"
CheckPerm = False
GrntDenySheetAccess nPermColTarget, y, x, CheckPerm
End If
End Function
Private Sub GrntDenySheetAccess(nPermColTarget As String, y As Integer, _
x As Integer, CheckPerm As Boolean)
Select Case nPermColTarget
' Sheet1
Case "Timesheet"
If CheckPerm = True Then
Sheet1.Unprotect "pass"
Sheet1.Visible = xlSheetVisible
End If
If CheckPerm = False Then
Sheet1.Protect "pass"
Sheet1.Visible = xlSheetVeryHidden
End If
End Select
End Sub
但即使 sheet1 被隐藏和保护,我仍然可以遍历隐藏 sheet1 的内容以访问信息。无论如何要阻止它?
谢谢