XL 2016 protéger feuille en autorisant Tri et Filtre

KTM

XLDnaute Impliqué
Bonsoir chers tous
Je voudrais protéger ma base de données mais en autorisant le filtre et le tri.
Manuellement cela est possible pour moi mais je voudrais savoir comment le faire à l'aide d'une macro.
j'ai concocté un code à l'aide de l'éditeur de macro mais le coté filtre et tri ne marche pas.
Veuillez me donner un coup de pouce. Merci..

VB:
Sub Protect()
Application.ScreenUpdating = False
With Sheets("BASE")
.Unprotect (1234)
.EnableSelection = xlNoRestrictions
.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowFormattingCells:=True, AllowFormattingColumns:=True, _
        AllowFormattingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
        AllowUsingPivotTables:=True
.Protect (1234)
End With
End Sub
 

Pièces jointes

  • protectTriFiltre.xlsm
    15.8 KB · Affichages: 2

TooFatBoy

XLDnaute Barbatruc
Bonjour,

Une proposition :
VB:
Sub Protect()
'
    Application.ScreenUpdating = False

    With Sheets("BASE")
        .Unprotect (1234)
        .EnableSelection = xlNoRestrictions
        .Protect Password:="1234", _
                DrawingObjects:=True, _
                Contents:=True, _
                Scenarios:=True, _
                AllowFormattingCells:=True, _
                AllowFormattingColumns:=True, _
                AllowFormattingRows:=True, _
                AllowSorting:=True, _
                AllowFiltering:=True, _
                AllowUsingPivotTables:=True
    End With

End Sub
 

KTM

XLDnaute Impliqué
Bonjour,

Une proposition :
VB:
Sub Protect()
'
    Application.ScreenUpdating = False

    With Sheets("BASE")
        .Unprotect (1234)
        .EnableSelection = xlNoRestrictions
        .Protect Password:="1234", _
                DrawingObjects:=True, _
                Contents:=True, _
                Scenarios:=True, _
                AllowFormattingCells:=True, _
                AllowFormattingColumns:=True, _
                AllowFormattingRows:=True, _
                AllowSorting:=True, _
                AllowFiltering:=True, _
                AllowUsingPivotTables:=True
    End With

End Sub
Merci pour tout!!
 

Statistiques des forums

Discussions
312 207
Messages
2 086 237
Membres
103 162
dernier inscrit
fcfg