Exportation en pdf non complète

Bonjour tout le monde,

j’ai un soucis avec une exportation en pdf.

Avec le code ci-dessous il doit exporter l’onglet qui comporte un TS. Or, il exporte bien une partie mais il n’exporte pas toutes les lignes du TS.

Suis-je obligé de définir la zone impression ? Car même si je le fais en allant jusqu’à la fin du TS, il ne m’exporte pas la ligne si j’en rajoute une autre.

Alors est-ce que vous pouvez voir une erreur juste en visualisant le code ci-dessous ?

Sub Archiver_Sortie_du_Jour()
Dim chemin As String

Application.ScreenUpdating = False

chemin = "P:\PRC VERSION 10\Archives SORTIES JOURNALIERES\"

Sheets("SORTIE DU JOUR").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
chemin & "Sortie_Journalière_" & "du_" & LaDate & "_" & "N°_ " & Range("D2") & " _ " & Range("F5") & " _ " & Range("D11") & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
From:=1, To:=1, OpenAfterPublish:=False
MsgBox "Document archivé"
End Sub

Merci d’avance à vous

Rubis

avec un petit effort pour la lisibilité et pourqu’on peut lancer la macro dans importe quelle feuille

Sub Archiver_Sortie_du_Jour()
     Dim Chemin As String, NomPDF

     Application.ScreenUpdating = False

     Chemin = "P:\PRC VERSION 10\Archives SORTIES JOURNALIERES\"
     With Sheets("????")                     'la feuille avec ces cellules D2,F5 et D11
          NomPDF = Chemin & "Sortie_Journalière_" & "du_" & LaDate & "_" & "N°_ " & .Range("D2") & " _ " & .Range("F5") & " _ " & .Range("D11") & ".pdf"
     End With

     Sheets("SORTIE DU JOUR").PivotTables(1).TableRange2.ExportAsFixedFormat xlTypePDF, NomPDF     'si c'est le premier TCD ou on n'a qu'un TCD
     Sheets("SORTIE DU JOUR").PivotTables("Nom du TCD").TableRange2.ExportAsFixedFormat xlTypePDF, NomPDF

     MsgBox "Document archivé"
End Sub


La construction With … End With et très important le point en face de « .range » vous aide à simplifier la macro, il ne faut plus répéter des choses
Pour exporter en pdf, seulement les 2 premiers paramètres sont important, le reste VBA prend leur valeur defaut.
On a 2 options là pour exporter le TCD en pdf, oubien avec l’index du TCD dans sa feuille oubien avec son nom.
TableRange1 et TableRange2 sont les 2 plages d’un TCD, normallement TableRange1 suffit quand on n’ a rien dans le « page »

Bonjour,

j’ai mis en place comme ceci

Sub Archiver_Sortie_du_Jour()
     Dim Chemin As String, NomPDF

     Application.ScreenUpdating = False

     Chemin = "P:\PRC VERSION 10\Archives SORTIES JOURNALIERES\"
     With Sheets("SORTIE DU JOUR")                     'la feuille avec ces cellules D2,F5 et D11
          NomPDF = Chemin & "Sortie_Journalière_" & "du_" & LaDate & "_" & "N°_ " & .Range("D2") & " _ " & .Range("F5") & " _ " & .Range("D11") & ".pdf"
     End With

     Sheets("SORTIE DU JOUR").PivotTables(1).TableRange2.ExportAsFixedFormat xlTypePDF, NomPDF     'si c'est le premier TCD ou on n'a qu'un TCD
     Sheets("SORTIE DU JOUR").PivotTables("Tab_S").TableRange2.ExportAsFixedFormat xlTypePDF, NomPDF

     MsgBox "Document archivé"
End Sub

mais j’ai une erreur

Sub Archiver_Sortie_du_Jour()
     Dim Chemin As String, NomPDF

     Application.ScreenUpdating = False

     Chemin = "P:\PRC VERSION 10\Archives SORTIES JOURNALIERES\"
     'Chemin = ThisWorkbook.Path & "\"        'mon chemin

     With Sheets("SORTIE DU JOUR")           'la feuille avec ces cellules D2,F5 et D11
          NomPDF = Chemin & "Sortie_Journalière_" & "du_" & LaDate & "_" & "N°_ " & .Range("D2") & " _ " & .Range("F5") & " _ " & .Range("D11") & ".pdf"
          MsgBox NomPDF
        
          MsgBox .PivotTables.Count & " TCDs" 'nombre de TCDs dans cette feuille
          Set c = .PivotTables(1).TableRange2
          MsgBox c.Address

          .PivotTables(1).TableRange2.ExportAsFixedFormat xlTypePDF, NomPDF     'si c'est le premier TCD ou on n'a qu'un TCD
          .PivotTables("Nom du TCD").TableRange2.ExportAsFixedFormat xlTypePDF, NomPDF
     End With

     MsgBox "Document archivé"
End Sub

quelques msgboxes supplémentaires pour mieux détecter l’erreur.

  • le nom du pdf : contient-il des charactères spéciaux interdits ? comme #@ etc. C’est quoi le nom ?
  • le nombre de TCDs dans cette feuille, c’est combien ?
  • il donne une réponse correcte pour la plage du TCD ?
  • il bloque sur la ligne « exportasfixedformat » ???

Vous comprenez la construction avec « With … End With ». Chaque fois que vous voyez quelque chose qui commence avec un point comme « .PivotTables(1).TableRange2 », on peut y ajouter "Sheets(« SORTIE DU JOUR ») « , donc cela sera Sheets(« SORTIE DU JOUR »).PivotTables(1).TableRange2 », donc plus facile et vite à écrire et plus lisible.

Voici mon code de départ, lequel me posait soucis. C’est à dire peut-on via ce code lui dire d’exporter le TS complet avec toutes les lignes .

Sub Archiver_Sortie_du_Jour()
Dim Chemin As String

Application.ScreenUpdating = False

Chemin = "P:\PRC VERSION 10\Archives SORTIES JOURNALIERES\"

Sheets("SORTIE DU JOUR").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
Chemin & "Sortie_Journalière_" & "du_" & LaDate & "_" & "N°_ " & Range("D2") & " _ " & Range("F5") & " _ " & Range("D11") & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
From:=1, To:=1, OpenAfterPublish:=False
MsgBox "Document archivé"
End Sub

Et voici votre code lequel j’ai adapté comme vous m’aviez demandé, mail bloque sur la ligne qui est en jaune dans l’avant dernier post ou j’ai placé les images.

Sub Archiver_Sortie_du_Jour()
     Dim Chemin As String, NomPDF

     Application.ScreenUpdating = False

     Chemin = "P:\PRC VERSION 10\Archives SORTIES JOURNALIERES\"
     With Sheets("SORTIE DU JOUR")                     'la feuille avec ces cellules D2,F5 et D11
          NomPDF = Chemin & "Sortie_Journalière_" & "du_" & LaDate & "_" & "N°_ " & .Range("D2") & " _ " & .Range("F5") & " _ " & .Range("D11") & ".pdf"
     End With

     Sheets("SORTIE DU JOUR").PivotTables(1).TableRange2.ExportAsFixedFormat xlTypePDF, NomPDF     'si c'est le premier TCD ou on n'a qu'un TCD
     Sheets("SORTIE DU JOUR").PivotTables("Tab_S").TableRange2.ExportAsFixedFormat xlTypePDF, NomPDF

     MsgBox "Document archivé"
End Sub

cette ligne bloque

     Sheets("SORTIE DU JOUR").PivotTables(1).TableRange2.ExportAsFixedFormat xlTypePDF, NomPDF     'si c'est le premier TCD ou on n'a qu'un TCD

moi, je pense qu’il n’y a aucun TCD dans « Sortie du jour » ?

Hello
en début de conversation, il parle d’un TS, pas d’un TCD

Salut taz,

Merci. Toi tu l’as bien remarqué. Parfois je ne sais plus comment expliquer.

oei, excusez-moi !!!

1 « J'aime »

re,

alors j’ai modifié ton code de cette façon et il me l’enregistre bien en pdf . !

Sub Archiver_Sortie_du_Jour()
     Dim Chemin As String, NomPDF

     Application.ScreenUpdating = False

     Chemin = "P:\PRC VERSION 10\Archives SORTIES JOURNALIERES\"
     With Sheets("SORTIE DU JOUR")                     'la feuille avec ces cellules D2,F5 et D11
          NomPDF = Chemin & "Sortie_Journalière_" & "du_" & LaDate & "_" & "N°_ " & .Range("D2") & " _ " & .Range("F5") & " _ " & .Range("D11") & ".pdf"
     End With

     Sheets("SORTIE DU JOUR").ListObjects("Tab_S").Range.ExportAsFixedFormat xlTypePDF, NomPDF      'si c'est le premier TCD ou on n'a qu'un TCD

     MsgBox "Document archivé"
End Sub

Merci à toi pour ce travail.

A une prochaine

1 « J'aime »

Ce sujet a été automatiquement fermé après 30 jours. Aucune réponse n’est permise dorénavant.