2016-07-04 77 views
0

使用Excel VBA,如何锁定具有多个不同变量的工作表,即允许用户使用自动筛选器和排序选项。使用多个保护变量保护Excel工作表

我有这个迄今为止得到:

工作表(“表1”)保护密码:=“密码”

我怎么写旁边允许用户: 选择UN /锁定单元格 格式列/行 排序 使用自动筛选

谢谢

+0

撤消它,我猜 – newguy

回答

0

有16个参数,你可以用满足Protect使用工作表的问题。这是基于一个代码示例关闭此MSDN文章:

Option Explicit 

Sub LockSheet() 

    Dim ws As Worksheet 

    Set ws = ThisWorkbook.Worksheets(1) 

    ws.Protect Password:="Foo", _ 
     DrawingObjects:=True, _ 
     Contents:=True, _ 
     Scenarios:=True, _ 
     UserInterfaceOnly:=True, _ 
     AllowFormattingCells:=True, _ 
     AllowFormattingColumns:=True, _ 
     AllowFormattingRows:=True, _ 
     AllowInsertingColumns:=True, _ 
     AllowInsertingRows:=True, _ 
     AllowInsertingHyperlinks:=True, _ 
     AllowDeletingColumns:=True, _ 
     AllowDeletingRows:=True, _ 
     AllowSorting:=True, _ 
     AllowFiltering:=True, _ 
     AllowUsingPivotTables:=True 

End Sub 
+0

谢谢罗宾! –

0

只是要添加到@Robin给出的答案,这里是URL到.PROTECT功能,你会发现它有用的阅读各有什么参数做,也有一些被认为是真的,有些是假的。

https://msdn.microsoft.com/en-us/library/office/ff840611.aspx

亲切的问候,

lewisthegruffalo

+0

谢谢刘易斯!罗宾已经提到这个链接;但是在你提到它之后,我又看了一眼,发现了更多有用的信息。再次感谢! –