Mise en page excel vers PDF en VBA
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 :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| 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...nstitreayk.jpg
Pour palier à ce problème j'utilise une macro qui adapte mon tabeau sur une page à l'aide de ce code :
Code:
1 2 3
| 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...nstitre3wl.jpg
Et quand j'insère mes graphiques cela me donne ça :
http://imageshack.us/photo/my-images...nstitre2sh.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