Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim n As Byte, c As Range, test As Boolean, fichier
With Sheets("Feuil1") 'nom de la feuille à adapter
.Activate
n = MsgBox("Imprimer en PDF ?", 3, "Imprimer")
If n = vbCancel Then Cancel = True: Exit Sub
Set c = .[B9]
test = c Like "N ###/##/####/MICROSOFT/EXCEL" And Format(Month(Date), "00") = Mid(c, 7, 2) And Year(Date) = Val(Mid(c, 10, 4))
c = IIf(test, "N " & Format(Val(Mid(c, 3, 3)) + 1, "000") & Mid(c, 6, 99), "N 001/" & Format(Date, "mm/yyyy") & "/MICROSOFT/EXCEL")
If n = vbYes Then
Cancel = True 'annule l'impression normale
fichier = ThisWorkbook.Path & "\" & c & " - " & .[D12] 'à adapter
Application.EnableEvents = False 'désactive les évènements
.ExportAsFixedFormat xlTypePDF, Replace(fichier, "/", " ") 'le slash / est un caratère interdit
Application.EnableEvents = True 'réactive les évènements
End If
End With
End Sub