sspatriots
Well-known Member
- Joined
- Nov 22, 2011
- Messages
- 585
- Office Version
- 365
- Platform
- Windows
I've started piecing some code together that I want to print various named ranges to a PDF file. The code below only shows me the named range "Page6" on Sheet3. The other two don't even print. Also, it needs to fit the whole page width, and right now it is only about 2/3 rds of the pages width in the PDF. I'm guessing I need to somehow redefine the margins, but not sure how to do this. The ranges of my pages are listed below:
Page1 ='Package Passenger'!$A$1:$AJ$54
Page2 ='Package Passenger'!$A$55:$AJ$109
Page3 ='Package Passenger'!$A$110:$AJ$164
Page4 ='Package Passenger'!$A$165:$AJ$218
Page5 ='Package Passenger'!$A$219:$AJ$273
Page6 ='Package Passenger'!$A$274:$AJ$328
Page7 ='Package Passenger'!$A$329:$AJ$377
This is the code I have to print just 3 of the pages. I will be writing two more macros after this that will print 2 other scenarios of pages.
Thanks, SS
Page1 ='Package Passenger'!$A$1:$AJ$54
Page2 ='Package Passenger'!$A$55:$AJ$109
Page3 ='Package Passenger'!$A$110:$AJ$164
Page4 ='Package Passenger'!$A$165:$AJ$218
Page5 ='Package Passenger'!$A$219:$AJ$273
Page6 ='Package Passenger'!$A$274:$AJ$328
Page7 ='Package Passenger'!$A$329:$AJ$377
This is the code I have to print just 3 of the pages. I will be writing two more macros after this that will print 2 other scenarios of pages.
VBA Code:
Sub PrintRangesToPDF()
Sheet3.PageSetup.PrintArea = "Page1"
Sheet3.PageSetup.PrintArea = "Page3"
Sheet3.PageSetup.PrintArea = "Page6"
Range("Page1, Page3, Page6").Select
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="My Three Sheets", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
With ActiveSheet.PageSetup
.Zoom = False
.Orientation = xlPortrait
.FitToPagesWide = 1
End With
End Sub
Thanks, SS