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 60 61 62 63 64 65 66 67 68 69 70 71
| Sub MEP_Cliquer()
ActiveSheet.ResetAllPageBreaks
With ActiveSheet.PageSetup
.PrintArea = "A1:H30"
.Orientation = xlPortrait
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
' ActiveSheet.PrintPreview
.PrintArea = "A31:H137"
.Orientation = xlPortrait
.FitToPagesWide = 1
.FitToPagesTall = False
CheckPage "A31:H137" 'Vérifier la structure de la page
' ActiveSheet.PrintPreview
.PrintArea = "A186:H309"
.Orientation = xlPortrait
CheckPage "A186:H309" 'Vérifier la structure de la page
' ActiveSheet.PrintPreview
.PrintArea = "A310:H322"
.Orientation = xlPortrait
.FitToPagesWide = 1
.FitToPagesTall = 1
' ActiveSheet.PrintPreview
.PrintArea = "A138:T185"
.Orientation = xlLandscape
' ActiveSheet.PrintPreview
End With
' Imprimer en PDF (version 2007 et + seulement)
' Ref: http://msdn.microsoft.com/en-us/library/office/bb238907(v=office.12).aspx
sRep = "T:\test" 'Répertoire de sauvegarde (si non spécifié, répertoire actif par défaut)
sFilename = ThisWorkbook.Name 'Nom du fichier
sFilename = Left(sFilename, InStr(1, sFilename, ".")) & "pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sRep & sFilename, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End Sub
Sub CheckPage(Plage)
Dim I As Long
Dim nbLignes As Long
nbLignes = Range(Plage).Row + Range(Plage).Rows.Count - 1
For I = Range(Plage).Row + 1 To nbLignes
If Rows(I).PageBreak = xlPageBreakAutomatic Then
FixPageBreak I, Range(Plage).Row
End If
Next
End Sub
Sub FixPageBreak(Ligne As Long, Debut As Long)
Dim I As Long
For I = Ligne To Debut Step -1
If Left(Range("A" & I), 3) Like "#.#" Or Left(Range("A" & I), 5) = "Cycle" Then
ActiveSheet.HPageBreaks.Add before:=Range("A" & I)
Exit For
End If
Next
End Sub |
Partager