Dear Readers,

In this article you are going to learn How to save an Excel Sheet as pdf file. Many a times we generate certain reports in an Excel Sheet but while sending that report to your boss, you want that to be saved in a PDF form. In such case you can simply save your Whole Sheet or a particular range from that sheet in PDF form. You can also Enter headers and footers in the Page Layout view in the Excel.

1. Code which export your active excel sheet as PDF


With ActiveSheet
    .ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:="C:\Users\Vish\File_Name.pdf", _ 
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False 
End With

2. Code which export any specific Sheet as PDF


With Sheets("Your Sheet Name")
    .ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:="C:\Users\Vish\File_Name.pdf", _ 
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False 
End With

3. Export a Specific Range from a Sheet as PDF


With Sheets("Your Sheet Name").Range("A1:F15")
    .ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:="C:\Users\Vish\File_Name.pdf", _ 
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False ' 
End With

Important:

Above code first split your Excel Sheet in Page View Layout as shown below and then it exports it in PDF form. Therefore, if you want to see how it should look like in PDF, you can go in Page View layout in Excel and see. You can also adjust the Margin in the layout. Also in the Layout View you can Add the Header and many more things like Page Number, Date Time etc which will not be seen in Normal View. But if you generate the pdf from that then those settings will reflect in your PDF file.

Export Excel as PDF - Layout

Export Excel as PDF - Layout



This is how your PDF file look like after exporting your Excel Sheet as PDF.

Export Excel as PDF

Export Excel as PDF