Gerasimos_Zap
New Member
- Joined
- Sep 23, 2015
- Messages
- 20
I have a report that I am trying to print with a VBA script. I need to print the report on one page (portrait) and have it centered. I have the formatting down pat, but the range is causing me issues. I need to set the print range to adjust to the number of values in the named range. Right now, it will print the named range, but it will not resize or print the new range if there have been entries added.
Code:
Sub PrintFailureReport()
Sheets("Failure Report").Activate
Range("FailReport").Select
ActiveSheet.PageSetup.PrintArea = Selection.Range("FailReport").Address
Application.PrintCommunication = True
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.25)
' .HeaderMargin = Application.InchesToPoints(0.3)
' .FooterMargin = Application.InchesToPoints(0.3)
.PrintGridlines = False
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlPortrait
.PaperSize = xlPaperLetter
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.BlackAndWhite = True
End With
Range("FailReport").PrintOut
End Sub