Print Selected Named Ranges to PDF

sspatriots

Well-known Member
Joined
Nov 22, 2011
Messages
585
Office Version
  1. 365
Platform
  1. 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.

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
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Thanks. That did the trick. I was tinkering with it over night to polish up and just made your small change there and it works like a charm. I posting the code below for anyone else that may come across this situation.

VBA Code:
Sub PowerUnitPrintRangesToPDF()
   
Dim Page1 As Range
Dim Page2 As Range
Dim Page3 As Range
Dim Page4 As Range
Dim Page5 As Range
Dim Page6 As Range
Dim Page7 As Range
Dim myMultipleRange As Range
     
Set Page1 = Sheets("Package Passenger").Range("A1:AJ54")
Set Page2 = Sheets("Package Passenger").Range("A55:AJ109")
Set Page3 = Sheets("Package Passenger").Range("A110:AJ164")
Set Page4 = Sheets("Package Passenger").Range("A165:AJ218")
Set Page5 = Sheets("Package Passenger").Range("A219:AJ273")
Set Page6 = Sheets("Package Passenger").Range("A274:AJ328")
Set Page7 = Sheets("Package Passenger").Range("A329:AJ380")

Set myMultipleRange = Union(Page1, Page3, Page6, Page7)
   
myMultipleRange.Select

Selection.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:="My Three Sheets", _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=True

    With ActiveSheet.PageSetup
    
        .LeftMargin = Application.InchesToPoints(0)
        .RightMargin = Application.InchesToPoints(0)
        .TopMargin = Application.InchesToPoints(0)
        .BottomMargin = Application.InchesToPoints(0)
        .CenterHorizontally = True
        .Orientation = xlPortrait
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = False
    
    End With

    ActiveWindow.View = xlNormalView
    Range("A1").Select

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top