Sub CommandeReçue()
' CommandeReçue Macro
' Mise en forme lors de la réception d'une ou plusieurs commandes
Dim mdp as [COLOR=red]Variant[/COLOR]
mdp = Application.InputBox("Tapez le mot de passe.", "MOT DE PASSE", Type:=2)
If mdp = "" Or mdp = False Then Exit Sub
On Error GoTo fin
ActiveSheet.Unprotect (mdp)
[COLOR=red]On Error GoTo 0 'annule la gestion des erreur (pas obligatoire mais c'est mieux)[/COLOR]
With Selection.Interior
.ColorIndex = 4
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect Password:=mdp, DrawingObjects:=True, Contents:=True, Scenarios:=True
[COLOR=red]Exit Sub '(j'avais oublié sinon le message apparait toujours)[/COLOR]
fin:
MsgBox "Mot de passe invalide !"
End Sub