Sub ProtectAllSheetsWithFiltering()
    Dim ws As Worksheet
    Dim strPassword As String
    strPassword = "123"  ' 自定义密码
    
    Application.ScreenUpdating = False
    
    On Error GoTo ErrorHandler
    
    For Each ws In ThisWorkbook.Worksheets
        If ws.ProtectContents Then
            ws.Unprotect password:=strPassword
        End If
        
        ws.Cells.Locked = True
        
        ' 保护参数配置(注释在行尾)
        ws.Protect password:=strPassword, _
                   AllowFiltering:=True, _
                   AllowUsingPivotTables:=True, _
                   AllowFormattingCells:=False, _
                   AllowFormattingColumns:=False, _
                   AllowFormattingRows:=False, _
                   AllowInsertingColumns:=False, _
                   AllowInsertingRows:=False, _
                   AllowDeletingColumns:=False, _
                   AllowDeletingRows:=False, _
                   AllowSorting:=False, _
                   DrawingObjects:=False, _
                   Contents:=True, _
                   Scenarios:=False
        
        If ws.AutoFilterMode Then
            ws.EnableAutoFilter = True
        End If
    Next ws
    
    Application.ScreenUpdating = True
    MsgBox "保护设置完成!", vbInformation
    Exit Sub
    
ErrorHandler:
    MsgBox "错误:" & Err.Description & vbCrLf & _
           "发生于工作表 [" & ws.Name & "]", vbCritical
    Application.ScreenUpdating = True
End Sub