Bonjour Hamouda,
Voici ... testé ...
Si le dossier "RENDEMENT" n'existe pas, il est créé ... s'il existe le code passe droit du bout "création du dossier" ...
Sub Création_PDF()
Dim Nom_PDF$
Call TesteSiDossierExiste
With ActiveSheet
Nom_PDF = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\RENDEMENT\" & .Name & ".pdf"
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Nom_PDF, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
MsgBox "Fichier PDF créé sous : " & vbLf & Nom_PDF, vbOKOnly + vbInformation
End With
End Sub
Sub TesteSiDossierExiste()
'' Source référence : https://excel.developpez.com/faq/?page=FichiersDir
Dim objShell As Object, objFolder As Object, objFolderItem As Object
Dim NomRep As String, DossierParent As String
Const Cible = &H10 ' < dossier Bureau de l'utilisateur en course
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(Cible)
Set objFolderItem = objFolder.self
DossierParent = objFolderItem.Path
NomRep = "RENDEMENT"
'Vérifie si le répertoire existe.
If Dir(DossierParent, vbDirectory + vbHidden) <> "" Then
'Vérifie que le dossier à créer n'existe pas déjà dans le répertoire
If Dir(DossierParent & "\" & NomRep, vbDirectory + vbHidden) = "" Then _
MkDir DossierParent & "\" & NomRep
End If
End Sub
ric