Option Explicit
Sub Créer_PDF_03()
Dim monDossier As String, monFichier As String
Dim sCommande As String, FSO As Object
monDossier = "C:\Test\Fiches"
monFichier = Feuil2.[k1]
sCommande = Environ("comspec") & " /c mkdir " & monDossier
Shell sCommande, 0
Delai 250
If NomFichierValide(monFichier) = False Then
Feuil2.[k1].Select
MsgBox "Nom de Fichier Invalide", vbOKOnly + vbCritical
Exit Sub
End If
With Feuil2
.PageSetup.BlackAndWhite = False
.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=monDossier & "\" & monFichier, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End With
End Sub
Private Function Delai(ByVal ms As Long)
Delai = Timer + ms / 1000
While Timer < Delai: DoEvents: Wend
End Function
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