Mise en page excel vers PDF en VBA

nyeri Messages postés 45 Date d'inscription vendredi 2 novembre 2007 Statut Membre Dernière intervention 29 février 2012 - 24 févr. 2012 à 10:03
nyeri Messages postés 45 Date d'inscription vendredi 2 novembre 2007 Statut Membre Dernière intervention 29 février 2012 - 24 févr. 2012 à 12:48
Bonjour,

Je vous expose mon problème.
J'ai un fichier excel qui me génère des feuilles automatique ou on y place des tableau et des graphiques. A la fin de la génération de ces documents je souhaite récupérer dans un fichier PDF toutes mes feuilles créé. Pour convertir mes feuilles excel en PDF j'utilise cette fonction qui marche très bien :

Sub ToPdf()

    Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
    NomExcel = ThisWorkbook.Name
    NomPdf = Left(NomExcel, Len(NomExcel) - 4) & ".pdf"
    
    With pdfjob
        If .cstart("/NoProcessingAtStartup") = False Then
            MsgBox "Can't initialize PDFCreator.", vbCritical + vbOKOnly, "PrtPDFCreator"
            Exit Sub
        End If
        .cOption("UseAutosave") = 1
        .cOption("UseAutisaveDirectory") = 1
        .cOption("AutosaveDirectory") = ThisWorkbook.Path
        .cOption("AutosaveFilename") = NomPdf
        .cOption("AutosaveFormat") = 0
        .cClearCache
    End With
    
    ThisWorkbook.PrintOut copies:=1, ActivePrinter:="PDFCreator"
    
    Do Until pdfjob.cCountOfPrintjobs = 1
        DoEvents
    Loop
    
    pdfjob.cPrinterStop = False
    
    Do Until pdfjob.cCountOfPrintjobs = 0
        DoEvents
    Loop
    
    With pdfjob
        .cDefaultprinter = DefaultPrinter
        .cClearCache
        .cClose
    End With
    
    Set pdfjob = Nothing

End Sub




Le problème que j'ai c'est que mes feuilles Excel sont trop large pour tenir sur une page PDF. Voir photo01



["http://imageshack.us/photo/my-images/210/sanstitreayk.jpg" http://imageshack.us/photo/my-images/210/sanstitreayk.jpg]

Pour palier à ce problème j'utilise une macro qui adapte mon tabeau sur une page à l'aide de ce code :

ActiveWindow.View = xlPageBreakPreview
        ActiveSheet.VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=1
        ActiveWindow.View = xlNormalView


Cela fonctionne bien et me donne ce résultat sur le PDF si je n'affiche pas mes graphique dans la mise en page.

["http://imageshack.us/photo/my-images/525/sanstitre3wl.jpg" http://imageshack.us/photo/my-images/525/sanstitre3wl.jpg]

Et quand j'insère mes graphiques cela me donne ça :

["http://imageshack.us/photo/my-images/141/sanstitre2sh.jpg" http://imageshack.us/photo/my-images/141/sanstitre2sh.jpg]

Voila quelqu’un pourrait il m'aider à palier ce problème, car je veut absolument afficher une feuille excel par page. Je suis ouvert à toute proposition.

Cordialement

2 réponses

cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 137
24 févr. 2012 à 12:20
Bonjour,
Tes liens sont cassés. Peut-être en imprimant en mode paysage?
Voici un site avec la macro pour mettre PDF Creator en mode paysage.

http://forum.excel-pratique.com/excel/mettre-en-vb-format-paysage-t5683-10.html

@+Le Pivert
0
nyeri Messages postés 45 Date d'inscription vendredi 2 novembre 2007 Statut Membre Dernière intervention 29 février 2012
24 févr. 2012 à 12:48
Merci je vais regarder ça ;)
0
Rejoignez-nous