Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

Macro avec beforesave

fmoore

XLDnaute Junior
Bonjour j'ai trouvé sur le net cette commande-ci :

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim Reponse As Variant

Reponse = Application.InputBox("Entrez votre identifiant", "Autorisation", , , , , , 2)

If VarType(Reponse) = vbBoolean Then
Reponse = MsgBox("Fichier non sauvegardé, Réessayer ?", vbYesNo)
If Reponse = vbYes Then ' L'utilisateur a choisi Oui.
Reponse = Application.InputBox("Entrez votre identifiant", "Autorisation", , , , , , 2)
If VarType(Reponse) = vbBoolean Then
MsgBox "Modifications perdues...", vbOKOnly
Cancel = True
ElseIf StrComp(Reponse, "MDP") <> 0 Then
Cancel = True
End If
Else ' L'utilisateur a choisi Non.
Cancel = True
End If
ElseIf StrComp(Reponse, "MDP") <> 0 Then
Reponse = MsgBox("Mot de passe érroné, Réessayer ?", vbYesNo)
If Reponse = vbYes Then ' L'utilisateur a choisi Oui.
Reponse = Application.InputBox("Entrez votre identifiant", "Autorisation", , , , , , 2)
If VarType(Reponse) = vbBoolean Then
MsgBox "Modifications perdues...", vbOKOnly
Cancel = True
ElseIf StrComp(Reponse, "MDP") <> 0 Then
Cancel = True
End If
Else ' L'utilisateur a choisi Non.
Cancel = True
End If
End If
End Sub




Elle fonctionne très bien sauf qu'elle fonctionne toutes les fois j'essaie d'enregistrer un fichier, mais j'aimerais seulement que la commande demande le mot de passe si j'essaie d'enregistrer par-dessus le chemin : "P:\Secrétariat et administration\Classeur1.xls". Est-ce que c'est possible ?

Merci de votre temps !
 

Discussions similaires

Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…