excel-to-pdf-vba-code

How to Convert Excel to PDF VBA

In this video, you will learn how to convert Excel sheet in PDF using VBA code. I have link a Salary slip format with row data of payroll employee and made it dynamic once serial number change in row number A1.

Copy and paste below code in your Excel VBA place and save your time and money.

Sub Create_PDF()
Dim Foldername, Filename, PDFPath, SR
Foldername = “C:\Users\USERNAME\Desktop\FOLDERNAME” ‘ Change it
For SR = 1 To 2
Sheets(“Pay Slip”).Range(“A1”).Value = SR
Filename = Sheets(“Pay Slip”).Range(“H7”).Value
PDFPath = Foldername & “\” & Filename & “.pdf”
Sheets(“PayRegister”).Visible = False
ActiveWorkbook.ExportAsFixedFormat xlTypePDF, PDFPath, xlQualityStandard, False
Sheets(“PayRegister”).Visible = True
Next SR
MsgBox “Successfully Saved”
End Sub