Gestion des zones d'impression en VBA
Bonjour,
J'ai développé un outil qui génère des factures sous excel.
Un fois la facture générée , je la convertie au format PDF en mode paysage. La macro fonctionne bien en utilisant cette macro.
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| Sub ZoneImpression()
Application.ScreenUpdating = False
DerLig = [A10000].End(xlUp).Row
DerCol = [Xfd1].End(xlToLeft).Column
Tableau = Cells(1, 1).Address & ":" & Cells(DerLig, DerCol).Address
Range(Tableau).Select
ActiveSheet.PageSetup.PrintArea = Tableau
ActiveWindow.View = xlPageBreakPreview
NbPage = ActiveSheet.HPageBreaks.Count + 1
ActiveWindow.View = xlNormalView
'Formatage avant impression
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0)
.RightMargin = Application.InchesToPoints(0)
.TopMargin = Application.InchesToPoints(0)
.BottomMargin = Application.InchesToPoints(0)
.HeaderMargin = Application.InchesToPoints(0)
.FooterMargin = Application.InchesToPoints(0)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = NbPage
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
'ExecuteExcel4Macro "PRINT(1,,,1,,TRUE,,,,,,1,,,TRUE,,FALSE)"
End Sub |
Le soucis c'est que chaque facture n'a pas toujours la même taille car plus ou moins de produit et les sauts de page automatique excel ne sont pas toujours bon.
Parfois le saut de page estime que la mise en page tiens sur une seule page et donc l'impression est compressé et ma facture n'occupe pas toute la largeur d'une feuille A4 ce qui rend la facture illisible.
Auriez vous une idée pour que chaque impression de facture occupe bien toute la largeur d'une feuille A4 au format paysage quelque soit la facture ?
Cdt
Shaka