Impression d'une feuille en VBA

Bonjour,

Dans un classeur , je rempli des zones de ma feuille par un formulaire

Je voudrais imprimer cette feuille en pdf dans un dossier lettre relance sur le bureau, j'ai démarrer ce code mais je ne sais pas comment lui faire selectionner

la zone d'impression de ma feuille Lettre.

' Chemin du dossier "Lettre de relance" sur le bureau
Dim folderPath As String
folderPath = desktopPath & "\Lettre de relance\"

' Créez le dossier s'il n'existe pas
If Dir(folderPath, vbDirectory) = "" Then
MkDir folderPath
End If

' Nom du fichier PDF
Dim fileName As String
fileName = "Relance_" & Me.Nom_du_Client.Value & "_" & Me.N_Facture.Value & "_" & Format(Date, "yyyy-mm-dd") & ".pdf"

' Chemin complet pour enregistrer le fichier PDF
Dim fullPath As String
fullPath = folderPath & fileName

' Enregistrez le document en PDF
' ActiveSheet.ExportAsFixedFormat OutputFileName:=fullPath, ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=FSheets("Lettre").Select
'Range("A1").Selectalse , OptimizeFor:=wdExportOptimizeForPrint, _
' IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:=wdExportCreateNoBookmarks

merci d'avance

ps merci de ml'indiquer comment mettre la discussion en resolu une fois fini

Bonjour, la macro VBA devrait ressembler à quelque chose comme ceci :

Sub ImprimerLettrePDF()
    Dim desktopPath As String
    Dim folderPath As String
    Dim fileName As String
    Dim fullPath As String
    Dim ws As Worksheet

    ' Définir la feuille à imprimer
    Set ws = ThisWorkbook.Sheets("Lettre") '/!\ Bien adapter le nom de la feuille

    ' Chemin du bureau
    desktopPath = Environ("USERPROFILE") & "\Desktop"

    ' Chemin du dossier "Lettre de relance"
    folderPath = desktopPath & "\Lettre de relance\"

    ' Créer le dossier s'il n'existe pas
    If Dir(folderPath, vbDirectory) = "" Then
        MkDir folderPath
    End If

    ' Nom du fichier PDF
    fileName = "Relance_" & ws.Range("Nom_du_Client").Value & "_" & ws.Range("N_Facture").Value & "_" & Format(Date, "yyyy-mm-dd") & ".pdf"

    ' Chemin complet
    fullPath = folderPath & fileName

    ' Définir la zone d'impression (exemple ici une plage nommée correspondant à A1:E30)
    ws.PageSetup.PrintArea = "Impression"   ' ? adapte selon ta zone utilise idéalement une plage nommée

    On Error GoTo Export_Err
    ' Exporter en PDF
    ws.ExportAsFixedFormat Type:=xlTypePDF, _
        fileName:=fullPath, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=True

    MsgBox "PDF enregistré dans : " & fullPath, vbInformation
    Exit Sub
Export_Err:
    MsgBox "Impossible d'exporter le PDF", vbExclamation
End Sub

En espérant avoir pu vous aider à progressé,

À bientôt.

je fais un essai et vous tiens au courant merci

Rechercher des sujets similaires à "impression feuille vba"