Excel VBA Export Worksheet or Workbook to PDF
Question details
The user needs to replace print-based VBA automation with code that exports an Excel worksheet or entire workbook directly to PDF.
- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- Automating PDF creation from an active worksheet or complete workbook with a specified output path.
- Observed behavior
- The existing print-based workflow needs to be replaced with Excel's built-in PDF export method.
Confirm that the workbook is saved in a location where macros can run and identify a valid output folder. Make sure the PDF filename includes the .pdf extension and that the target folder already exists.
Use ExportAsFixedFormat for an active worksheet
Use this method when the macro should create a PDF from only the currently active worksheet while respecting its print area.
Excel's ExportAsFixedFormat method creates a PDF directly and does not require a printer driver. Set IgnorePrintAreas to False when the worksheet's configured print area should control the output.
In the VBA editor, declare a PDFPath variable and assign it a valid folder and filename ending in .pdf, such as PDFPath = "C:\Path\To\Your\File.pdf".
Add ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFPath, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False to the macro.
Return to Excel, select the worksheet to export, and run the macro from Developer > Macros or by pressing Alt+F8. Excel saves the generated PDF at the path specified in PDFPath.
Export the entire Excel workbook to PDF
Use this option when every worksheet in the workbook should be included in one PDF file.
Create PDF Files from Spreadsheets with WPS Office
WPS Office provides a free, lightweight spreadsheet alternative for opening and editing Excel workbooks, then exporting worksheets or complete workbooks to PDF through a familiar interface. It supports Microsoft Excel XLS and XLSX formats for a smoother migration, although Excel-specific VBA methods such as ExportAsFixedFormat may require Microsoft Excel for execution.
- 1. Open the workbook: Launch WPS Spreadsheet and choose Menu > Open to load the Excel XLS or XLSX workbook.
- 2. Choose the PDF export command: Select Menu > Export to PDF or use the PDF toolbar option, depending on the WPS Office version.
- 3. Select the spreadsheet scope: Choose the active worksheet or the complete workbook in the PDF export settings, then review page and print-area options.
- 4. Save the PDF: Choose an output folder, enter a filename ending in .pdf, and select Export or Save to create the PDF.

Frequently Asked Questions
What VBA method exports an active Excel worksheet to PDF?
Use ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFPath, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False. Replace PDFPath with a valid .pdf file path.
How do I export the entire Excel workbook instead of one sheet?
Replace ActiveSheet with ActiveWorkbook: ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFPath. This exports the workbook according to its sheet and print settings.
Why should I use ExportAsFixedFormat instead of Microsoft Print to PDF?
ExportAsFixedFormat creates the PDF directly through Excel and does not depend on a printer driver. It is generally more reliable for unattended VBA automation.
What should the PDFPath variable contain?
PDFPath must contain an existing folder path and a filename ending in .pdf, such as C:\Reports\MonthlySales.pdf. Invalid folders or missing file extensions can prevent the export.
How do print areas affect the exported PDF?
When IgnorePrintAreas is set to False, Excel uses the worksheet or workbook print areas. Set it to True if the export should ignore configured print areas and use the broader sheet content.




