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 72 73 74 75 76 77 78 79 80 81 82 83
| Private Sub MiseEnPage()
Dim nbLignes As Long
Dim Fin1 As Long, Fin2 As Long
Dim sActivePrinter As String
sActivePrinter = Application.ActivePrinter
nbLignes = Cells(Rows.Count, "B").End(xlUp).Row
ActiveSheet.PageSetup.PrintArea = "$A$1:$AL$" & nbLignes
ActiveSheet.PageSetup.PaperSize = xlPaperLegal
Application.ActivePrinter = FindPrinter("Microsoft XPS Document Writer")
nbLignes = Cells(Rows.Count, "B").End(xlUp).Row
Range("C1").Select
Selection.End(xlDown).Select: Fin1 = ActiveCell.Row + 1
Selection.End(xlDown).Select
Selection.End(xlDown).Select: Fin2 = ActiveCell.Row + 1
ActiveSheet.PageSetup.PrintArea = "$A$1:$AL$" & nbLignes
With ActiveSheet.PageSetup
.RightFooter = "&P/&N"
.LeftMargin = Application.InchesToPoints(0.17)
.RightMargin = Application.InchesToPoints(0.17)
.TopMargin = Application.InchesToPoints(0.34)
.BottomMargin = Application.InchesToPoints(0.38)
.HeaderMargin = Application.InchesToPoints(0.18)
.FooterMargin = Application.InchesToPoints(0.17)
.Orientation = xlLandscape
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
End With
'Sauts de page
ActiveWindow.View = xlPageBreakPreview
ActiveSheet.HPageBreaks.Add before:=Range("A" & Fin1)
ActiveSheet.HPageBreaks.Add before:=Range("A" & Fin2)
ActiveWindow.View = xlNormalView
Application.ActivePrinter = sActivePrinter
End Sub
'Written: November 28, 2009
'Author: Leith Ross
'Summary: Finds a printer by name and returns the printer name and port number.
Function FindPrinter(ByVal PrinterName As String) As String
'This works with Windows 2000 and up
Dim Arr As Variant
Dim Device As Variant
Dim Devices As Variant
Dim Printer As String
Dim RegObj As Object
Dim RegValue As String
Const HKEY_CURRENT_USER = &H80000001
Set RegObj = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
RegObj.enumvalues HKEY_CURRENT_USER, "Software\Microsoft\Windows NT\CurrentVersion\Devices", Devices, Arr
For Each Device In Devices
RegObj.getstringvalue HKEY_CURRENT_USER, "Software\Microsoft\Windows NT\CurrentVersion\Devices", Device, RegValue
If Application.International(xlCountrySetting) = 2 Then
Printer = Device & " sur " & Split(RegValue, ",")(1)
Else
Printer = Device & " on " & Split(RegValue, ",")(1)
End If
If InStr(1, Printer, PrinterName, vbTextCompare) > 0 Then
FindPrinter = Printer
Exit Function
End If
Next
End Function |
Partager