Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save as PDF in Landscape

Tags:

excel

vba

How can I pdf multiple sheets in my Workbook into one pdf in landscape format? Here is what I have. I am missing the landscape syntax -

Sub CompileReport()

    Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="F:\Report\Test" & ".pdf", _
    Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False


End Sub

Thanks!

like image 872
Chris2015 Avatar asked Apr 16 '14 19:04

Chris2015


People also ask

Why won't my PDF print landscape?

Open the File menu, select "Print" and locate the Page Handling options. Uncheck "Auto-Rotate and Center" and click on the Page Setup button. Change page orientations and click on the "OK" button to print your document. 3.


1 Answers

Try this one:

Sub CompileReport()
    Dim mySheets As Variant, sh

    mySheets = Array("Sheet1", "Sheet2", "Sheet3")
    For Each sh In mySheets
        Sheets(sh).PageSetup.Orientation = xlLandscape
    Next

    Sheets(mySheets).Select
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="F:\Report\Test" & ".pdf", _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
End Sub
like image 60
Dmitry Pavliv Avatar answered Oct 02 '22 04:10

Dmitry Pavliv