vba 限制用户不能修改excel的内容
发布网友
发布时间:2022-04-21 22:03
我来回答
共5个回答
热心网友
时间:2023-09-22 20:37
替换成这个代码:Select Case sgrade
Case "管理员"
Application.ActiveWindow.DisplayWorkbookTabs = 1
Worksheets("用户权限").Visible = 1
Worksheets("基础表1").Visible = 1
Worksheets("查询系统").Visible = 1
ActiveSheet.Protect Password:="123", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True
UserForm1.Hide
Application.WindowState = xlMaximized
Case "普通用户"
Application.ActiveWindow.DisplayWorkbookTabs = False
Worksheets("用户权限").Visible = False
Worksheets("基础表1").Visible = False
Worksheets("查询系统").Visible = 1
ActiveSheet.Unprotect Password:="123"
UserForm1.Hide
Application.WindowState = xlMaximized
End Select
End If
End If 加粗的字为密码,可以自己设定,两个密码必须是一样的
热心网友
时间:2023-09-22 20:37
方法:
Select Case sgrade
Case "管理员"
Application.ActiveWindow.DisplayWorkbookTabs = 1
Worksheets("用户权限").Visible = 1
Worksheets("基础表1").Visible = 1
Worksheets("查询系统").Visible = 1
UserForm1.Hide
Application.WindowState = xlMaximized
Case "普通用户"
Application.ActiveWindow.DisplayWorkbookTabs = False
Worksheets("用户权限").Visible = False
Worksheets("基础表1").Visible = False
Worksheets("查询系统").Visible = 1
UserForm1.Hide
Application.WindowState = xlMaximized
End Select
End If
End If
热心网友
时间:2023-09-22 20:38
在Application.WindowState = xlMaximized后加上
Dim bar As CommandBarControl
For Each bar In Application.CommandBars("Worksheet Menu Bar").Controls(6).Controls
If bar.Caption = "保护(&P)" Then bar.Enabled = False
Next
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFiltering:=True, AllowUsingPivotTables:=True
退出时加上如下代码。
Dim bar As CommandBarControl
For Each bar In Application.CommandBars("Worksheet Menu Bar").Controls(6).Controls
If bar.Caption = "保护(&P)" Then bar.Enabled = True
Next
ActiveSheet.Unprotect
热心网友
时间:2023-09-22 20:38
工具→保护工作表,设置密码
热心网友
时间:2023-09-22 20:39
把不让修改的表“工具--保护--保护工作表”或“格式--工作表--隐藏”处理一下,估计可行。