Exporting a Range in Excel 2010 to PDF Format

Hi, How do I fit a range into a pdf page ( presumably it is sized to A4 / portrait ).

The code as follows:

Sub TestExportAsFixedFormat()
 
  Dim rng As Range
  Set rng = Range("A1:L100")
 
  Dim fileName As String
  fileName = "C:\Test\Export.pdf"
 
  rng.ExportAsFixedFormat Type:=xlTypePDF, _
   fileName:=fileName, Quality:=xlQualityStandard, _
   IncludeDocProperties:=True, IgnorePrintAreas:=True, _
   From:=1, To:=1, OpenAfterPublish:=True
End Sub

Thank you.
RussellbrownAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Harry LeeCommented:
The following code should work for you.

Sub TestExportAsFixedFormat()
 
    Dim rng As Range, OrgPntArea As String, NewPntArea As String, fileName As String
    Set rng = Range("A1:L" & ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row)
    fileName = "C:\Test\Export.pdf"

    OrgPntArea = ActiveSheet.PageSetup.PrintArea
    NewPntArea = Range("A1:L" & ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row).Address
    ActiveSheet.PageSetup.PrintArea = NewPntArea

    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
        .Orientation = xlPortrait
        .PaperSize = xlPaperA4
        .FitToPagesWide = 1
        .FitToPagesTall = False
    End With
    Application.PrintCommunication = True

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _
        fileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=True

    ActiveSheet.PageSetup.PrintArea = OrgPntArea

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.