Problème de macro
Résolu
playa2
-
playa2 -
playa2 -
Bonjour,
J'ai un petit souci avec ma macro qui fonctionne bien mais ne tient pas compte de la désactivation de protection et remise en protection à la fin :
Private Sub Workbook_Open()
ActiveSheet.Unprotect
For Each work In Worksheets
work.Activate
With work
If work.Name <> "Accueil" And work.Name <> "MDG" Then
selection.AutoFilter
selection.AutoFilter Field:=6, Criteria1:="1"
selection.AutoFilter Field:=4, Criteria1:="=A", Operator:=xlOr, _
Criteria2:="<>0"
End If
End With
Next work
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowSorting:=True, _
AllowFiltering:=True
End Sub
En effet, je reçois un message d'erreur 1004 me demandant d'enlever la protection de la feuille....
y a t'il une erreur dans ma macro ???
Merci de votre aide.
J'ai un petit souci avec ma macro qui fonctionne bien mais ne tient pas compte de la désactivation de protection et remise en protection à la fin :
Private Sub Workbook_Open()
ActiveSheet.Unprotect
For Each work In Worksheets
work.Activate
With work
If work.Name <> "Accueil" And work.Name <> "MDG" Then
selection.AutoFilter
selection.AutoFilter Field:=6, Criteria1:="1"
selection.AutoFilter Field:=4, Criteria1:="=A", Operator:=xlOr, _
Criteria2:="<>0"
End If
End With
Next work
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowSorting:=True, _
AllowFiltering:=True
End Sub
En effet, je reçois un message d'erreur 1004 me demandant d'enlever la protection de la feuille....
y a t'il une erreur dans ma macro ???
Merci de votre aide.
A voir également:
- Problème de macro
- Telecharger macro convertir chiffre en lettre excel - Télécharger - Tableur
- Jitbit macro recorder - Télécharger - Confidentialité
- Télécharger macro convertir chiffre en lettre excel - Télécharger - Tableur
- Macro maker - Télécharger - Divers Utilitaires
- Macro word - Guide
2 réponses
Bonjour
Il faut mettre cette ligne avant de remettre la protection
llowFiltering = True
Je ne suis pas anglophone mais je pense que c'est le problème
Il faut mettre cette ligne avant de remettre la protection
llowFiltering = True
Je ne suis pas anglophone mais je pense que c'est le problème
Merci pour la réponse mais il faut également déplacer la demande de désactivation de la protection de feuille de cette façon :
For Each work In Worksheets
work.Activate
With work
If work.Name <> "Accueil" And work.Name <> "MDG" Then
Range("AK1").Select
ActiveSheet.Unprotect
selection.AutoFilter Field:=6, Criteria1:="1"
selection.AutoFilter Field:=4, Criteria1:="=A", Operator:=xlOr, _
Criteria2:="<>0"
End If
End With
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowSorting:=True, _
AllowFiltering:=True
Next work
End Sub
Maintenant ça fonctionne bien !!!
For Each work In Worksheets
work.Activate
With work
If work.Name <> "Accueil" And work.Name <> "MDG" Then
Range("AK1").Select
ActiveSheet.Unprotect
selection.AutoFilter Field:=6, Criteria1:="1"
selection.AutoFilter Field:=4, Criteria1:="=A", Operator:=xlOr, _
Criteria2:="<>0"
End If
End With
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowSorting:=True, _
AllowFiltering:=True
Next work
End Sub
Maintenant ça fonctionne bien !!!