Sub pdf()
Dim fusion As MailMerge
Dim x As Integer, nb As Integer
Dim chemin As String, nom As String
Dim fichierPDF As String
Set fusion = [Link]
' ? Toujours terminer le chemin par un anti-slash "\"
chemin = "C:\Users\korgo\Downloads\publi\"
' ? Crée le dossier s’il n'existe pas
If Dir(chemin, vbDirectory) = "" Then MkDir chemin
nb = [Link]
For x = 0 To nb - 1
With fusion
.[Link] = x + 1
.[Link] = x + 1
.Destination = wdSendToNewDocument
.[Link] = x + 1
nom = .[Link](2).Value
.Execute
End With
' ? Nettoyage du nom (remplace les caractères interdits)
nom = Trim(nom)
nom = Replace(nom, "\", "_")
nom = Replace(nom, "/", "_")
nom = Replace(nom, ":", "_")
nom = Replace(nom, "*", "_")
nom = Replace(nom, "?", "_")
nom = Replace(nom, """", "_")
nom = Replace(nom, "<", "_")
nom = Replace(nom, ">", "_")
nom = Replace(nom, "|", "_")
' ? Assemblage du chemin complet + vérification
fichierPDF = chemin & "Contrat_" & nom & ".pdf"
' ? Exporter le document actif en PDF
[Link] OutputFileName:=fichierPDF,
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False
[Link] savechanges:=False
Next
MsgBox "? Fusion terminée avec succès ! Fichiers enregistrés dans :" & vbCrLf & chemin,
vbInformation
End Sub
Sub InsertionZoneSignatureVisible()
Dim zone As Shape
Dim texte As String
texte = "? Signature du bénéficiaire :"
' Créer une zone de texte avec ligne de signature simulée
Set zone = [Link]( _
Orientation:=msoTextOrientationHorizontal, _
Left:=100, Top:=600, Width:=400, Height:=50)
With zone
.[Link] = texte & vbCrLf & "___________________________"
.[Link] = "Calibri"
.[Link] = 12
.[Link] = msoTrue
.[Link] = RGB(0, 0, 0)
.[Link] = msoFalse
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Left = InchesToPoints(2)
.Top = InchesToPoints(7.5)
End With
End Sub