Need to increase the PDF print area

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Before I convert my chart over to a PDF, I do a print preview to make sure everything is going to fit onto 8.5 inch x 11 inch paper and it looks like it will. That being said, I, when I run the code below, and when it gets to the "openafterpublish", it cuts off the bottom part of my chart. Is there a way to adjust the print area size with VBA code? Here's what I have so far. Thank you in advance.

VBA Code:
Private Sub cmdbtnPDF_Save_Click()
    Dim sPath As String
    Dim sFilename As String
    Dim wbAnswer As Integer
        
       
    sPath = "C:\Users\" & Environ("username") & "\Desktop\Save PDF Test\"
        
    sFilename = Range("E2").Text & "_" & Format(Now, "mm.dd.yyyy") & ".pdf"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sFilename, IgnorePrintAreas:=True, openafterpublish:=True, IncludeDocProperties:=False
    ActiveWorkbook.Save
    wbAnswer = MsgBox("Are you sure you want to close this workbook and Excel?", vbYesNo + vbDefaultButton1 + vbQuestion, "WORKBOOK: " & ActiveWorkbook.Name)
    If wbAnswer = vbYes Then
        ActiveWorkbook.Save
        Application.Quit
    Else
        Exit Sub
    End If
    
End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try this:

VBA Code:
Private Sub cmdbtnPDF_Save_Click()
    Dim sPath As String
    Dim sFilename As String
    Dim wbAnswer As Integer
        
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = xlPrintNoComments
        .CenterHorizontally = False
        .CenterVertically = False
        .Orientation = xlPortrait
        .Draft = False
        .PaperSize = xlPaperLetter
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
        .PrintErrors = xlPrintErrorsDisplayed
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
    End With
     
    sPath = "C:\Users\" & Environ("username") & "\Desktop\Save PDF Test\"
        
    sFilename = Range("E2").Text & "_" & Format(Now, "mm.dd.yyyy") & ".pdf"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sFilename, IgnorePrintAreas:=True, openafterpublish:=True, IncludeDocProperties:=False
    ActiveWorkbook.Save
    wbAnswer = MsgBox("Are you sure you want to close this workbook and Excel?", vbYesNo + vbDefaultButton1 + vbQuestion, "WORKBOOK: " & ActiveWorkbook.Name)
    If wbAnswer = vbYes Then
        ActiveWorkbook.Save
        Application.Quit
    Else
        Exit Sub
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,104
Members
453,021
Latest member
Justyna P

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