Save as pdf, max page space

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,832
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
The code below saves Sheet1 and Sheet2 as a single pdf.

Code:
With ThisWorkbook
               
    Dim SaveFile As Variant
                
    SaveFile = Application.GetSaveAsFilename(InitialFileName:=Left(String:=.FullName, _
                                                                                                  Length:=(InStrRev(StringCheck:=.FullName, StringMatch:=".", Start:=-1, Compare:=vbTextCompare) - 1)) & ".pdf", FileFilter:="PDF files, *.pdf", _
             Title:="Save workbook as pdf")
                                                         
                    With Sheet1.PageSetup

                        .PrintArea = "$A$1:$R$50"
                        .CenterHorizontally = True
                        .CenterVertically = True
                        .Orientation = xlLandscape
                        .PaperSize = xlPaperA4
                        .FitToPagesWide = 1
                        .FitToPagesTall = 1
                    End With


                With Sheet2.PageSetup

                        .PrintArea = "$A$1:$S$60"
                        .CenterHorizontally = True
                        .CenterVertically = True
                        .Orientation = xlLandscape
                        .PaperSize = xlPaperA4
                        .FitToPagesWide = 1
                        .FitToPagesTall = 1
                    End With
                    
                    .Worksheets(Array(Sheet1.Name, Sheet2.Name)).Select
                            
                    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
                                                    Filename:=SaveFile, _
                                                    Quality:=xlQualityStandard, _
                                                    IncludeDocProperties:=True, _
                                                    IgnorePrintAreas:=True, _
                                                    OpenAfterPublish:=False
                                                                
              
            
        End With
        
    Next Counter

The problem is there are big spaces on the page around the sides. In page preview in Excel, it maximises the use of the page but not when it's a pdf.

How can I change this?

Thanks
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,214,845
Messages
6,121,902
Members
449,053
Latest member
Guy Boot

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