Private Sub Workbook_BeforeSave(ByVal SaveAsUi As Boolean, Cancel As Boolean)
Dim der%, nom$, chemin$, wb As Workbook
With Sheets("Facture de service")
.Activate
der = InStr(.[C10], ":")
If der = 0 Then MsgBox _
"Il faut : (2 points) après ""Nom"" en C10 !!", 48: Exit Sub
nom = Application.Trim(Mid(.[C10], der + 1))
nom = Application.Proper(nom) 'majuscule en tête pour le classement
If nom = "" Then
MsgBox "Le nom n'a pas été entré..."
.[C10].Select
Else
Cancel = True
chemin = Me.Path & "\" 'chemin du dossier à adapter
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
'---création du fichier facture .pdf---
MkDir chemin & nom 'création du sous-dossier s'il n'existe pas
.ExportAsFixedFormat xlTypePDF, chemin & nom & "\" & .[F4]
If Dir(chemin & nom & "\*") = "" Then _
MsgBox "Caractère interdit dans le nom !", 48: Exit Sub
NomMemo = .[C10] 'mémorisation
'---mémorisation du numéro de facture---
Workbooks("Numero_Facture").Close False 'si le fichier est ouvert
Set wb = Workbooks.Add(xlWBATWorksheet)
.[F4].Copy wb.Sheets(1).[A1]
wb.Sheets(1).Protect "TOTO" 'mot de passe à adapter
wb.SaveAs chemin & "Numero_Facture" 'enregistrement
wb.Close
End If
End With
End Sub