Commande excel avec Workbook_BeforeSave

Fermé
Francis - 20 oct. 2014 à 21:42
via55 Messages postés 14405 Date d'inscription mercredi 16 janvier 2013 Statut Membre Dernière intervention 25 avril 2024 - 20 oct. 2014 à 22:41
Bonjour,


Avec Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Est-ce qu'il est possible d'empêcher les utilisateurs d'enregistrer par-dessus le fichier modèle sauf si la personne connait le mot de passe ?

Merci de votre aide.
A voir également:

3 réponses

via55 Messages postés 14405 Date d'inscription mercredi 16 janvier 2013 Statut Membre Dernière intervention 25 avril 2024 2 703
20 oct. 2014 à 21:58
Bonsoir

Pas besoin de passer par du VBA l'option est prévue par Excel

Faire Enregistrer sous
Donner un nouveau nom au fichier
Cliquez en bas sur Outils puis Options générales
Entrer le mot de passe

Cdlmnt

0
En fait il faut que la personne puisse l'enregistrer sous un autre endroit.

J'ai trouvé ceci qui pourrait m'aider.

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

Mon seul problème est qu'il le lance à chaque fois j'essaie d'enregistrer je voudrais il me demande seulement si j'essaie d'enregistrer sous : "P:\Secrétariat et administration\Classeur1.xls"

Merci de votre temps !
0
via55 Messages postés 14405 Date d'inscription mercredi 16 janvier 2013 Statut Membre Dernière intervention 25 avril 2024 2 703
20 oct. 2014 à 22:41
0