Option Explicit
Sub SauverPDF()
Dim sFichier As String
Dim sCell As String
sCell = "M13"
sFichier = Feuil1.Range(sCell)
If NomFichierValide(sFichier) Then
Feuil1.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=ThisWorkbook.Path & "\" & sFichier, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
From:=1, To:=1, _
OpenAfterPublish:=False
Application.StatusBar = "Fichier pdf créé"
Else
With Feuil1
.Activate
.Range(sCell).Select
End With
Application.StatusBar = "Nom de Fichier INVALIDE"
End If
End Sub
Private Function NomFichierValide(sChaine As String) As Boolean
Dim i As Long
Const sCaracInterdits As String = """*/:<>?[\]|"
NomFichierValide = True
If Len(sChaine) = 0 Then
NomFichierValide = False
Exit Function
End If
For i = 1 To Len(sCaracInterdits)
If InStr(sChaine, Mid$(sCaracInterdits, i, 1)) > 0 Then
NomFichierValide = False
Exit Function
End If
Next i
End Function