How to Export an Excel Sheet as PDF file

.

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

Buy a coffee for the author

Adsense

Download FREE Tools and Templates

There are many cool and useful excel tools and templates available to download for free. For most of the tools, you get the entire VBA code base too which you can look into it, play around it, and customize according to your need.

Convert PDF Tables to Excel with VBA | Step-by-Step Guide
Convert PDF Tables to Excel with VBA | Step-by-Step Guide

Convert PDF Tables to Excel with VBA | Step-by-Step Guide How to Convert PDF Tables to Excel Using Excel VBA (Macros) Extracting data from PDF tables into Excel can be tedious, but with Excel VBA (macros), you can automate this process and save time. This guide will...

Dynamic Arrays and Spill Functions in Excel: A Beginner’s Guide
Dynamic Arrays and Spill Functions in Excel: A Beginner’s Guide

In today's tutorial, we'll be diving into the exciting world of dynamic arrays and spill functions in Office 365 Excel. These features have revolutionized the way we work with data, providing a more flexible and efficient way to handle arrays. I am going to explain...

How to Declare a Public Variable in VBA
How to Declare a Public Variable in VBA

While programming in VBA sometimes you need to declare a Public Variable that can store the value throughout the program. Use of Public Variable: Let's say you have 4 different Functions in your VBA Code or Module and you have a variable that may or may not be...

What is Excel Formula?

Excel Formula is one of the best feature in Microsoft Excel, which makes Excel a very very rich application. There are so many useful built-in formulas available in Excel, which makes our work easier in Excel. For all the automated work, Excel Macro is not required. There are so many automated things can be done by using simple formulas in Excel. Formulas are simple text (With a Syntax) which is entered in to the Excel Worksheet Cells. So how computer will recognize whether it is a formula or simple text? Answer is simple.. every formula in Excel starts with Equal Sign (=).

You May Also Like…

9 Comments

  1. Roxana

    Hello,

    How can use “Export a Specific Range from a Sheet as PDF” to export in a ppt file?
    I saw that the method “ExportAsFixedFormat ” is used for pdf and xps file..
    Is there any method to export in ppt directly?
    Thank you very much and have a nice day 🙂

    Reply
  2. Sarvesh

    It gives me an error

    Run time error ‘5’
    Invalid procedure call or argument

    please help

    Reply
  3. Dheeraj

    Hi

    If i want that every time it save file with a new file name then what will be the code.

    Reply
  4. Govardhan

    Awesome Vishwamitra.
    Its working perfectly as per my requirement.
    THANKS A TON!!!

    Reply
  5. Binu

    I get below error as well. any help is appreciated.

    Run time error ‘5’
    Invalid procedure call or argument

    Thanks!
    Binu

    Reply
    • Vishwamitra Mishra

      Hi Binu,
      Can you please highlight statement where you get this error?

      Reply
  6. Deepa

    Hi Vishwamitra,
    I have one doubt on it actually this article about export excel file to PDF file right but in your code choosing fileneme in PDF format???can you please explain about it.

    Reply
  7. Aaron Kelly

    Hi Vishwamitra,
    I had this code running for years on my Windows 7 Office 2010 excel. I recently upgraded my computer and moved to Office 365. Now, this code does not work.

    I get the runtime error ‘-2147417848 (80010108)’:
    Automation Error
    The Object invoked has disconnected from its clients.

    When I debug the yellow arrow indicates
    OpenAfterPublish:=False

    Reply

Trackbacks/Pingbacks

  1. Learn Excel Macro Send Sheet as a PDF attachment in Email - [...] Readers,   In my previous article, you saw how to save an Excel Sheet as PDF file. Now you…

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Join and get a FREE! e-Book

Don't miss any articles, tools, tips and tricks, I publish here

You have Successfully Subscribed!

Pin It on Pinterest