在Workbook对象级别上有以下代码,但它不允许自动过滤或取消分组列。
Private Sub Workbook_Open()
For Each ws In Sheets
With ws
.Protect Password:="xxxxxxxx", Userinterfaceonly:=True,
AllowFormattingColumns:=True, AllowFormattingRows:=True, _
AllowFiltering:=True, AllowInsertingRows:=True,
AllowSorting:=True, AllowDeletingRows:=True
End With
Next ws
End Sub