Welcome to FreeSoftwareServers Confluence Wiki

https://stackoverflow.com/questions/23957735/excel-vba-print-margin-seems-to-be-ignored

https://docs.microsoft.com/en-us/office/vba/api/excel.sheets.printout

'''''PRINT'''''
Public Sub SetPrinterToDuplex() 'Not Working
    Dim sPrinterName
    sPrinterName = "EPSON60798C (WF-2630 Series)"
    SetPrinterDuplex sPrinterName, 2
End Sub

Public Sub PrintSetup()

Const xlLandscape = 2

With Application
 With .ActiveSheet
 With .Pagesetup
  .Orientation = xlPortrait
  .Zoom = False
  .FitToPagesWide = 1
  .FitToPagesTall = False
  .LeftMargin =  0.75
  .RightMargin =  0.25
  .TopMargin =  0.75
  .BottomMargin = 0.75
  .HeaderMargin = 0.3
  .FooterMargin = 0.3
  .PrintTitleRows = "$1:$1"
  .PrintTitleColumns = ""
 End With
 '.PrintPreview 'Use PrintPreview for Debugging
 '.PrintOut ActivePrinter:="\\%SERVER%\%PRINTER%" 'Hard Code Printer
 '.PrintOut ActivePrinter:="EPSON60798C (WF-2630 Series)" 'Print via Specific Printer 
 '.PrintOut  'Generic Print via Default
 End With
 .Dialogs(xlDialogPrint).Show
End With
With Application
 .DisplayAlerts = False 'No Save Dialogue
 .Quit
End With
End Sub
'''''ENDPRINT'''''
FindLast

Dim wsrng As Range
Set wsrng = ws.Range("A2:I" & lRow)

With wsrng
 .EntireColumn.AutoFit
 .Borders.LineStyle = xlContinuous
 .BorderAround Weight:=xlMedium
End With

With ws.PageSetup
 .Orientation = xlLandscape
 .FitToPagesWide = 1
 .FitToPagesTall = False
 .PrintTitleRows = "$1:$1"
 .PrintTitleColumns = ""
 .RightHeader = Format(Now(), "dddd, mmmm dd, yyyy")
 .RightFooter = "Page &P of &N"
End With

End Sub
  • No labels