willow1985
Well-known Member
- Joined
- Jul 24, 2019
- Messages
- 929
- Office Version
- 365
- Platform
- Windows
I have this code that adjusts the print area based on the report the person is wanting to print, but lately it is printing double the pages. For example if the report happens to be 7 pages, it will have 7 pages plus an additional 7 that are blank when I look at print preview.
I am wondering if this is because of the columns that are hidden in the macro.
I am not sure 100% this is the problem but figured it was a good start
So my question is: Is there a way to set the PrintArea for a table for visible cells only?
See below code and thank you to anyone who can help!
I am wondering if this is because of the columns that are hidden in the macro.
I am not sure 100% this is the problem but figured it was a good start
So my question is: Is there a way to set the PrintArea for a table for visible cells only?
See below code and thank you to anyone who can help!
VBA Code:
Sub Hearing_Testing()
'
' Hearing_Testing Macro
'
Columns("A:A").EntireColumn.Hidden = True
Columns("D:F").EntireColumn.Hidden = True
Columns("H:H").EntireColumn.Hidden = True
Columns("K:P").EntireColumn.Hidden = True
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = "Emp_Listing[#All]" 'wondering if this line is my issue, printing the whole table even the hidden columns?? Change to visible only?
Application.CutCopyMode = False
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = "$2:$2"
.PrintTitleColumns = ""
End With
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.354330708661417)
.RightMargin = Application.InchesToPoints(0.354330708661417)
.TopMargin = Application.InchesToPoints(0.984251968503937)
.BottomMargin = Application.InchesToPoints(0.984251968503937)
.HeaderMargin = Application.InchesToPoints(0.511811023622047)
.FooterMargin = Application.InchesToPoints(0.511811023622047)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 120
.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
Application.PrintCommunication = True
End Sub