Exporter Excel en PDF via VBA "fenêtre enregistrer sous "

Bonjour,

J'ai créé un code pour exporter une feuille active en PDF

et j'aimerais plutôt que de définir le dossier d'enregistrement d'avoir à la place la fenêtre "enregistrer sous "

Est-ce possible ?

MErci

Sub PDF_SAVE()

Dim LHeure As String, LeDate As String

' Création d'une copie pour l'export PDF

ActiveSheet.Copy after:=Sheets(Sheets.Count)
sFilename = ActiveSheet.Range("A39").Value

' Création fichier PDF

ActiveSheet.Shapes.Range(Array("Rectangle 3")).Select
Selection.Delete
ActiveSheet.Shapes.Range(Array("Rectangle 2")).Select
Selection.Delete
ActiveSheet.Shapes.Range(Array("Rectangle 1")).Select
Selection.Delete

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"D:\Desktop\Planning " & sFilename & " .pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
From:=1, To:=1, OpenAfterPublish:=False

' Message de confirmation

MsgBox ("Planning Mensuel " & sFilename & " exporté en PDF" & vbCrLf & vbCrLf & "Merci ")

' Supprimer la feuille d'export

Application.DisplayAlerts = False
ActiveSheet.Delete

End Sub

Edit modo : code mis entre balises, merci d'y faire attention

Hello,

Tu peux utiliser cette instruction :

Application.Dialogs(xlDialogSaveAs).Show

Merci fonctionne nickel

Je peux déjà forcer l'extension PDF ?

Edit:

Application.Dialogs(xlDialogSaveAs).Show sFilename, 57

C'est bon Merci

Possible d'adapter un message si au moment d'enregistrer en pdf l'utilisateur annule ??

Sub PDF_SAVE()

Dim sFilename As String

' Création d'une copie pour l'export PDF

ActiveSheet.Copy after:=Sheets(Sheets.Count)
sFilename = ActiveSheet.Range("A39").Value

' Création fichier PDF

ActiveSheet.Shapes.Range(Array("Rectangle 3")).Select
Selection.Delete
ActiveSheet.Shapes.Range(Array("Rectangle 2")).Select
Selection.Delete
ActiveSheet.Shapes.Range(Array("Rectangle 1")).Select
Selection.Delete

Application.Dialogs(xlDialogSaveAs).Show sFilename, 57

' Message de confirmation

MsgBox ("Planning Mensuel " & sFilename & " exporté en PDF" & vbCrLf & vbCrLf & "Merci ")

' Supprimer la feuille d'export

Application.DisplayAlerts = False
ActiveSheet.Delete

End Sub

Hello,

If Application.Dialogs(xlDialogSaveAs).Show(sFilename, 57) Then

Si tu cliques sur annuler, alors tu ne rentres pas dans le if

Effectivement ça fonctionne bien

mais j'ai le souci que la feuille créée pour l'export ne se supprime pas si j'annule l'enregistrement en pdf....

Car au début du code j'efface les 3 boutons sur lesquels j'ai affecté 3 macros

j'atteins mes limites sur excel et VBA ...

Sub PDF_SAVE()

Dim sFilename As String

' Création d'une copie pour l'export PDF

ActiveSheet.Copy after:=Sheets(Sheets.Count)
sFilename = ActiveSheet.Range("A39").Value

' Création fichier PDF et suppression des boutons macros

ActiveSheet.Shapes.Range(Array("Rectangle 3")).Select
Selection.Delete
ActiveSheet.Shapes.Range(Array("Rectangle 2")).Select
Selection.Delete
ActiveSheet.Shapes.Range(Array("Rectangle 1")).Select
Selection.Delete

If Application.Dialogs(xlDialogSaveAs).Show(sFilename, 57) Then

' Message de confirmation

MsgBox ("Planning Mensuel " & sFilename & vbCrLf & vbCrLf & " Exporté en PDF ")

' Supprimer la feuille d'export

Application.DisplayAlerts = False
ActiveSheet.Delete

End If
End Sub

Si dans tous les cas tu dois supprimer ta feuille alors :

If Application.Dialogs(xlDialogSaveAs).Show(sFilename, 57) Then

' Message de confirmation

MsgBox ("Planning Mensuel " & sFilename & vbCrLf & vbCrLf & " Exporté en PDF ")
End If
' Supprimer la feuille d'export

Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True

ahhhhhhhhhhhhhhhhhh

Parfait Merci

Rechercher des sujets similaires à "exporter pdf via vba fenetre enregistrer"