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.
This is how your PDF file look like after exporting your Excel Sheet as PDF.
Very use ful thank you
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 🙂
It gives me an error
Run time error ‘5’
Invalid procedure call or argument
please help
Hi
If i want that every time it save file with a new file name then what will be the code.
Awesome Vishwamitra.
Its working perfectly as per my requirement.
THANKS A TON!!!
I get below error as well. any help is appreciated.
Run time error ‘5’
Invalid procedure call or argument
Thanks!
Binu
Hi Binu,
Can you please highlight statement where you get this error?
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.
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