You can customize the output by specifying additional arguments in the PrintOut method. For example, you can specify the printer, paper size, and orientation.
Here is an example code snippet that prints the active worksheet to PDF and saves it: excel vba print to pdf and save
vb Copy Code Copied ActiveWorkbook.PrintOut However, to print to PDF, you need to specify the PrintToFile argument and set it to True . You also need to specify the OpenAfterPublish argument and set it to False . You can customize the output by specifying additional
vb Copy Code Copied Sub PrintToPDF() Dim filename As String You also need to specify the OpenAfterPublish argument
The PrintOut method is used to print a worksheet or workbook. To print to PDF, you can use the PrintOut method with the ActiveSheet or ActiveWorkbook object. The basic syntax is:
vb Copy Code Copied Sub PrintToPDF() Dim filename As String
filename = "C:\Path\To\Save\" & "Report_" & Format(Now, "yyyy-mm-dd_hh-mm-ss") & ".pdf" ActiveSheet.PrintOut PrintToFile:=True, PrintFilename:=filename, OpenAfterPublish:=False End Sub