How to save Workbook/worksheet as a PDF, which is mostly used with the ExportasfixedformaT method, to convert workbook, Sheet, Chart, or range to PDF or XPS format
1 Subconvertsheettopdf ()2 DimFileName as String3FileName = Application.getsaveasfilename (initialfilename:="", filefilter:="PDF Files (*.pdf), *.pdf", title:="Select Path and FileName to save")4 IfFileName <>"False" Then5 withActiveWorkbook6. Worksheets ("Sheet1"). ExportAsFixedFormat Type:=xltypepdf, filename:= _7FileName, Quality:=xlqualitystandard, includedocproperties:=True, ignoreprintareas:=False, openafterpublish:=False8 End with9 End IfTen End Sub
The parameters and descriptions are described in more detail on MSDN:
Name |
Required/Optional |
Data type |
Description |
Type |
Necessary |
Xlfixedformattype |
It can be xltypepdf or xltypexps. |
Filename |
Options available |
Variant |
A string that indicates the name of the file to save. You can include the full path, or Excel will save the file in the current folder. |
Quality |
Options available |
Variant |
Can be set to Xlqualitystandard or xlqualityminimum. |
Includedocproperties |
Options available |
Variant |
Set to True to indicate that document properties should be included, or set to False to indicate that document properties should be omitted. |
Ignoreprintareas |
Options available |
Variant |
If set to True, any print areas that are set at publish time are ignored. If set to False, the print area that is set when publishing is used. |
From |
Options available |
Variant |
The starting page number of the publication. If this argument is omitted, the publication starts at the starting position. |
To |
Options available |
Variant |
The ending page number of the publication. If this argument is omitted, it is published to the last page. |
Openafterpublish |
Options available |
Variant |
If set to True , the file is displayed in the viewer after publishing. If set to False , the file is published but not displayed. |
Fixedformatextclassptr |
Options available |
Variant |
A pointer to the Fixedformatext class. |
How to Convert a workbook/worksheet to PDF