Setting Print Area (Fit to Page) when saving ranges to PDF via macro...Please Help.

rcicconetti

New Member
Joined
Jan 16, 2016
Messages
34
I have a scheduling program that runs in Excel. One macro saves 7 ranges to a PDF file. The ranges, however go beyond the print limits and thus render 14 pages of PDF instead of the intended 7 pages (referring to 7 days in the week). Can someone help me to have each range "Fit to Page,"
so that when I print the PDF I only get 7 neat pages.

Code:
Sub savetopdf()
'
' savetopdf Macro
'
   Dim saveFileName As String
    Dim PDFranges As Range
    
    With ActiveSheet
        saveFileName = CreateObject("WScript.Shell").SpecialFolders("MyDocuments") & .Range("T3").Value & ".pdf"
    
        Set PDFranges = .Range("X3:AC52,AE3:AJ52,AL3:AQ52,AS3:AX52,AA59:AF111,AH59:AM111,AO59:AT111")
    End With
    
    PDFranges.ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveFileName, _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
'
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try setting the page margins to the minimum to make each range fit on 1 page: Page Layout -> Margins. Record a macro whilst you do this and you can call the macro from your code to repeat the page setup every time you create the PDF.
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,629
Members
449,241
Latest member
NoniJ

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