How to create pdf from ListBox in Excel VBA

 If you want to create or generate pdf for LisBox's data then you need to follow few simple steps as follow..

Step1. Populate ListBox data from worksheet as you need. Step2. You need to Transfer all data from ListBox to worksheet(Specified) Step3. In this Step you should define the path where your pdf file will be saved Step4. Create pdf file of Specified worksheet ## If you want to learn how to populate or display data on ListBox then click the below link.. # Populate or Display data on ListBox as you type on TextBox or based on TextBox's keywords https://youtu.be/zaPpkWYnAN4 # Display searched data on ListBox with more than 10 column (17 Column) https://youtu.be/i1k7Vz9Q-iU

VBA codes are given below.........
insert a commanbutton on your userform and double click on it and write the codes below

Private Sub CommandButton8_Click()
' create pdf from listbox
Sheets("Report").Cells.ClearContents
Dim r As Long
For r = 0 To Me.ListBox1.ListCount - 1
With Sheets("Report").Range("A" & Rows.Count).End(xlUp)

.Offset(1, 0) = Me.ListBox1.List(r, 0) '  data will transfer from listbox's 1st column
.Offset(1, 1) = Me.ListBox1.List(r, 1) ' data will transfer from listbox's 2nd column
.Offset(1, 2) = Me.ListBox1.List(r, 2)
.Offset(1, 3) = Me.ListBox1.List(r, 3)
.Offset(1, 4) = Me.ListBox1.List(r, 4)
.Offset(1, 5) = Me.ListBox1.List(r, 5)
.Offset(1, 6) = Me.ListBox1.List(r, 6)
.Offset(1, 7) = Me.ListBox1.List(r, 7)

End With
Next r
Dim myPath As String
With Sheets("Report")
.Range("C:C").WrapText = True
.Range("A2:H2").Font.Bold = True
myPath = "D:\Voucher\" & "Report-" & Date & ".pdf" ' create a folder named as Voucher in D drive
.PageSetup.Orientation = xlLandscape
.ExportAsFixedFormat xlTypePDF, Filename:=myPath, Openafterpublish:=True
End With
End Sub

For Support and feedback
Please subscribe my channel

No comments:

Post a Comment