Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Chemin As String, MyFile As String
Range("F1:G1").Select
SaveAsUI = False
Cancel = True
With Worksheets(NomFeuille)
Select Case Left(.Range("F10"), 1)
Case "D": Chemin = "C:\"
'Case "F": Chemin = CheminDossierFacture
End Select
If Dir(Chemin, vbDirectory) = "" Then
MsgBox "Le répertoire devis n'existe pas !" & Chr(10) & "Le devis sera enregistré sur le bureau de votre ordinateur", vbInformation, "Répertoire inexistant"
Chemin = "C:\Users\" & Application.UserName & "\Desktop\"
End If
MyFile = Chemin & .Range("F10") & .Range("G10").Text & Chr(160) & "-" & Chr(160) & .Range("A12") & Chr(160) & "(" & .Range("F14") & ")" & ".xlsm"
End With
If Dir(MyFile) <> "" Then
If MsgBox("Un devis nommé '" & MyFile & "' existe déjà à cet emplacement." & Chr(10) & Chr(10) & "Voulez-vous la remplacer ?", vbQuestion + vbYesNo + vbDefaultButton2, "Devis déjà existant") <> vbYes Then
MsgBox "Le devis n'a pas été enregistré !", vbInformation, "Annulation"
Exit Sub
End If
End If
Application.EnableEvents = False
Application.DisplayAlerts = False
Me.SaveAs MyFile
Application.DisplayAlerts = False
Application.EnableEvents = True
MsgBox "Le devis a bien été enregistré !", vbInformation, "Confirmation"
End Sub