I have the below code that works perfectly to generate multiple forms based on a table data. However the forms produced are in XLS format and i would like them to automatically save to PDF. How can i amend the code to automatically generate PDF forms rather than excel documents?
Option Explicit
Sub GenerateForms()
Dim wSrc As Workbook
Dim sSrc As Worksheet
Dim wTrg As Workbook
Dim sTrg As Worksheet
Dim r As Long
Dim m As Long
Application.ScreenUpdating = False
Set wSrc = ThisWorkbook
Set sSrc = wSrc.Worksheets("Passenger Vehicles")
m = sSrc.Range("B" & sSrc.Rows.Count).End(xlUp).Row
For r = 2 To m
Select Case sSrc.Range("A" & r).Value
Case "Standard"
wSrc.Worksheets("Declaration").Copy
Case "Supervisor"
wSrc.Worksheets("Supervisory Review").Copy
End Select
Set wTrg = ActiveWorkbook
Set sTrg = wTrg.Worksheets(1)
sTrg.Range("F6").Value = sSrc.Range("E" & r).Value
sTrg.Range("C8").Value = sSrc.Range("G" & r).Value
sTrg.Range("F8").Value = sSrc.Range("H" & r).Value
sTrg.Range("C9").Value = sSrc.Range("C" & r).Value
sTrg.Range("F9").Value = sSrc.Range("I" & r).Value
sTrg.Range("C10").Value = sSrc.Range("K" & r).Value
sTrg.Range("F10").Value = sSrc.Range("J" & r).Value
sTrg.Range("C27").Value = sSrc.Range("E" & r).Value
sTrg.Range("F27").Value = sSrc.Range("D" & r).Value
' Optional: save and close the review workbook
wTrg.SaveAs Filename:=wSrc.Path & "\" & sSrc.Range("B" & r).Value & ".PDF", _
FileFormat:=xlTypePDF
wTrg.Close SaveChanges:=False
Next r
Application.ScreenUpdating = True
End Sub
Option Explicit
Sub GenerateForms()
Dim wSrc As Workbook
Dim sSrc As Worksheet
Dim wTrg As Workbook
Dim sTrg As Worksheet
Dim r As Long
Dim m As Long
Application.ScreenUpdating = False
Set wSrc = ThisWorkbook
Set sSrc = wSrc.Worksheets("Passenger Vehicles")
m = sSrc.Range("B" & sSrc.Rows.Count).End(xlUp).Row
For r = 2 To m
Select Case sSrc.Range("A" & r).Value
Case "Standard"
wSrc.Worksheets("Declaration").Copy
Case "Supervisor"
wSrc.Worksheets("Supervisory Review").Copy
End Select
Set wTrg = ActiveWorkbook
Set sTrg = wTrg.Worksheets(1)
sTrg.Range("F6").Value = sSrc.Range("E" & r).Value
sTrg.Range("C8").Value = sSrc.Range("G" & r).Value
sTrg.Range("F8").Value = sSrc.Range("H" & r).Value
sTrg.Range("C9").Value = sSrc.Range("C" & r).Value
sTrg.Range("F9").Value = sSrc.Range("I" & r).Value
sTrg.Range("C10").Value = sSrc.Range("K" & r).Value
sTrg.Range("F10").Value = sSrc.Range("J" & r).Value
sTrg.Range("C27").Value = sSrc.Range("E" & r).Value
sTrg.Range("F27").Value = sSrc.Range("D" & r).Value
' Optional: save and close the review workbook
wTrg.SaveAs Filename:=wSrc.Path & "\" & sSrc.Range("B" & r).Value & ".PDF", _
FileFormat:=xlTypePDF
wTrg.Close SaveChanges:=False
Next r
Application.ScreenUpdating = True
End Sub