+ Reply to Thread
Results 1 to 3 of 3

Macro to save to PDF and retain 11x17 landscape

Hybrid View

  1. #1
    Registered User
    Join Date
    08-10-2012
    Location
    California, US
    MS-Off Ver
    Excel 2007
    Posts
    1

    Macro to save to PDF and retain 11x17 landscape

    Hello all,

    I need to save an Excel worksheet to PDF and retain it's paper size of 11 x 17 landscape. Below is the macro I currently have and it runs but saves the pdf in 11 x 8.5. Any help is greatly appreciated.


    Sub CreatePDF()
    'Creates an individual workbook for each worksheet in the active workbook.
    Dim wbSource As Workbook
    Dim sht As Worksheet 
    Dim strPeriod As String
    Dim sFileName As String
    
    
    Application.Goto (ActiveWorkbook.Sheets("Sheet1").Range("b2"))
    strPeriod = ActiveCell.Value
    
    Application.ScreenUpdating = False
    
    Set wbSource = ActiveWorkbook
    Sheets("Sheet1").Select
    Set sht = wbSource.Worksheets("Sheet1")
    sFileName = "c:\Temp\Test\" & sht.Name & " " & strPeriod & ".pdf"
     ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            sFileName, Quality:=xlQualityStandard _
            , IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
            False
    Last edited by Cutter; 09-07-2012 at 06:51 PM. Reason: Added code tags

  2. #2
    Registered User
    Join Date
    09-07-2012
    Location
    Milton Keynes, UK
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Macro to save to PDF and retain 11x17 landscape

    Hi Dougl,

    Just set the page orientation before you print using the sheet.pagesetup method/member

    Sub CreatePDF()
    'Creates an individual workbook for each worksheet in the active workbook.
    Dim wbSource As Workbook
    Dim sht As Worksheet 
    Dim strPeriod As String
    Dim sFileName As String
    
    
    Application.Goto (ActiveWorkbook.Sheets("Sheet1").Range("b2"))
    strPeriod = ActiveCell.Value
    
    Application.ScreenUpdating = False
    
    Set wbSource = ActiveWorkbook
    Sheets("Sheet1").Select
    Set sht = wbSource.Worksheets("Sheet1")
    
    With sht.PageSetup
      .PaperSize = xlPaper11x17     '<<< Sets your page size
      .Orientation = xlLandscape
    End With
    
    sFileName = "c:\Temp\Test\" & sht.Name & " " & strPeriod & ".pdf"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    sFileName, Quality:=xlQualityStandard _
    , IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
    False
    
    End Sub
    Last edited by arcticsponge; 09-07-2012 at 09:23 AM. Reason: Forgot to add the orientation member

  3. #3
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Macro to save to PDF and retain 11x17 landscape

    @ Dougl

    Welcome to the forum.

    Please notice that code tags have been added to your post(s). The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at top of the page and read Rule #3.
    Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1