vba export worksheet as pdf in Excel

Q187. In Excel, how can I export a WorkSheet as a PDF using VBA?

To do it in Excel, here is the answer:

  1. Option Explicit
  2. Sub ExportAsPDF()
  3. Dim sOutputFolderPath As String, sFileName As String
  4. ''
  5. sOutputFolderPath = "C:\Users\Guest\Documents\TestFolder\"
  6. sFileName = sOutputFolderPath & "PDF_Export_Example.pdf"
  7. ''
  8. Export ActiveSheet as PDF.
  9. ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
  10. ''
  11. End Sub

Description:

a) Line 9 - ActiveSheet is exported as a PDF in the Output folder specified with assigned filename. If required, print settings need to be applied prior to exporing PDF.

 

You can find similar Excel Questions and Answer hereunder

1) How can I remove Outline from my WorkSheet?

2) How can I identify the cells that influence a particular cell to help with debugging of my spreadSheet or understand a spreadSheet that I inherited?

3) How can I filter and copy only filtered data using VBA?

4) Vba to return week numbers in Excel

5) How do I restrict user entry in ActiveX Text Box to just numeric values?

6) How can I sort data using VBA?

7) How can I add a background image to a worksheet?

8) How can I get users to select a file for processing using my macro?

9) How can I set Page orientation, Zoom % , Title Rows and footer using VBA?

10) I have a macro that takes a lot of time for execution - how can I keep the user informed that the macro is running?

11) Userform initialize vs userform show in Excel

12) How can I convert Column numbers into Column names for use in range definition?

13) How can I get row count of filtered data?

14) How can I dynamically add a hyperlink using VBA?

15) How can I insert a watermark in my Worksheet?