VBA print to PDF - autofit to one page

jon1315

Board Regular
Joined
Jun 16, 2020
Messages
60
Office Version
  1. 365
Platform
  1. Windows
Good morning
I have an issue with a piece of code where I'm unable to fit the pdf export to one page - the end column always spills onto a second PDF page.
The code attached is part of a larger project, which all works fine, apart from this one export. I don't have much experience with page layouts within vba and googling can't get me close enough!

VBA Code:
                                                Range("a1:s" & lrow2).Copy
                                                Set WBCIR = Workbooks.Add
                                                Range("a1").PasteSpecial (xlPasteValues)
                                                Range("A:V").EntireColumn.AutoFit
                                                ActiveSheet.PageSetup.PrintArea = "a1:s10"
                                                Range("A:A").EntireColumn.Delete
                                                WBCIR.SaveAs Filename:=SaveFP & CustomerID & " " & CaseNumber & ".xlsx"
                                                Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:=SaveFP & CustomerID & " " & CaseNumber & ".pdf"
                                                WBCIR.Close
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Before you save/create the PDF, add this bit of code and see if it works for you:
VBA Code:
    With ActiveSheet.PageSetup
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With
 
Upvote 0

Forum statistics

Threads
1,214,389
Messages
6,119,232
Members
448,879
Latest member
VanGirl

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