


Set cht = ws.ChartObjects("Chart 1").ChartĬht.ExportAsFixedFormat Type:=xlTypePDF, _ 'Create and assign variables Dim saveLocation As String Dim ws As Worksheet The VBA code below saves a specified chart as a PDF. Rng.ExportAsFixedFormat Type:=xlTypePDF, _ 'Create and assign variables Dim saveLocation As String Dim ws as Worksheet The macro below saves a specified range as a PDF. Selection.ExportAsFixedFormat Type:=xlTypePDF, _ Sometimes, we only want to save a small part of a worksheet to a PDF. The following code prints only the selected cells. Sub SaveActiveWorkbookAsPDF()ĪctiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, _ Use the following macro to save all the visible sheets from a workbook. SaveLocation = "C:\Users\marks\OneDrive\Documents\myPDFFile.pdf"ĪctiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _ 'Create and assign variables Dim saveLocation As String The following code saves the selected sheets as a single PDF. This section contains the base code to save Excel as PDF from different objects (workbooks, worksheets, ranges, and charts). From a VBA perspective, it is the ExportAsFilxedFormat method combined with the Type property set to xlTypePDF that creates a PDF. Saving Excel workbooks, sheets, charts, and ranges as PDF Other fixed formats available (xlTypeXPS).VBA Save to PDF Example using all the options.Selecting specific worksheets before saving as PDF.Saving Excel workbooks, sheets, charts, and ranges as PDF.
