VBA:如何允许filter在受保护的页面上打开和closures?

我有下面这段代码,删除filter,然后重新应用它们从选定的单元格:

Range("A10:AM10").Select Selection.AutoFilter Selection.AutoFilter 

我遇到的问题是,当表被保护,我试图运行代码错误,那么有没有办法允许filter打开和closures在受保护的工作表上?

你好吗?

这将取决于保护的设置。 当您保护工作表时,有一个选项允许过滤(自动过滤)。

如果您是保护工作表的人员,则可以使用任何工作表的保护方法参数来设置保护选项。 这里是保护方法的参数:

 sheetName.Protect(Password, DrawingObjects, Contents, Scenarios, UserInterfaceOnly, AllowFormattingCells, AllowFormattingColumns, AllowFormattingRows, AllowInsertingColumns, AllowInsertingRows, AllowInsertingHyperlinks, AllowDeletingColumns, AllowDeletingRows, AllowSorting, AllowFiltering, AllowUsingPivotTables) 

如果您希望只能通过代码实现filter,则可以将UserInterfaceOnly参数设置为TRUE。 该保护将仅阻止用户更改。 代码更改将被完全允许。

 sheetName.Protect UserInterfaceOnly:=True 

或者,如果要允许用户从界面过滤工作表的内容,只需将AllowFiltering参数设置为TRUE以及UserInterfaceOnly参数即可。

 sheetName.Protect UserInterfaceOnly:=True, AllowFiltering:=True 

你的代码应该与两个选项一起工作。

希望能帮助到你!