Sub Puplipostage()
Dim Ws1 As Worksheet, Ws2 As Worksheet
Dim LoR As Range, i&, Cptr&
Set Ws1 = Worksheets("Feuil1")
Set Ws2 = Worksheets("Publipostage")
Set LoR = Ws1.ListObjects(1).Range
Application.ScreenUpdating = False
For i = 2 To LoR.Rows.Count
If LoR(i, 13) = "A faire" Then
Ws2.Range("B8,B17,C18:C20,B24,B26").Interior.ColorIndex = xlNone
Select Case LoR(i, 12)
Case "PM"
Ws2.Range("B8") = Ws2.Range("H5") & LoR(i, 11) & Ws2.Range("H9")
Case "ASVP"
Ws2.Range("B8") = Ws2.Range("H5") & LoR(i, 11) & Ws2.Range("H12")
Case Else 'Si besoin on rajoute des case.....
Ws2.Range("B8") = Ws2.Range("H5") & LoR(i, 11) & Ws2.Range("H15")
End Select
Ws2.Range("B17") = "Le " & Format(LoR(i, 1) + LoR(i, 2), "dddd d mmmm yyyy à hh:mm") & _
", " & LoR(i, 3) & " " & LoR(i, 4) & " " & LoR(i, 5) & " le véhicule : "
Ws2.Range("C18:C20") = Application.Transpose(LoR(i, 8).Resize(, 3))
Ws2.Range("B24") = LoR(i, 7)
Ws2.Range("B26") = "Cette infraction a pu être relevée au moyen de la caméra " & _
LoR(i, 6) & ", et a fait l’objet d’une verbalisation par procès-verbal électronique."
LoR(i, 13) = "Fait"
'*********** PDF
With Ws2.PageSetup
.PrintArea = "$A$1:$F$52" 'Plage à imprimer
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Ws2.ExportAsFixedFormat xlTypePDF, ThisWorkbook.Path & "\" & LoR(i, 10) & ".pdf" 'Nomn du PDF ==> Immatriculation de la voiture
'***********
Cptr = Cptr + 1
End If
Next i
'***** RAZ de la feuille publipostage
Ws2.Range("B8,B17,C18:C20,B24,B26") = ""
Ws2.Range("B8,B17,C18:C20,B24,B26").Interior.Color = vbYellow
'*****
MsgBox "Nombre de PDF créé : " & Cptr, vbInformation, "Création PDF"
End Sub