patrice33740 a écrit :
Bonjour,
Le nombre de pages et le nombre de sections c'est pas la même chose, (même si dans ton document ils sont identiques). Il faut être cohérent dans le code.
Essaies comme ça :
Code :
- Option Explicit
- Sub Impression()
- '
- ' Impression Macro
- '
- Dim nom As String
- Dim prenom As String
- Dim nomPdf As String
- Dim i As Integer
- With ActiveDocument
- For i = 1 To .Sections.Count
- nom = ActiveDocument.Sections(i).Range.Paragraphs(16).Range.Words(3)
- prenom = ActiveDocument.Sections(i).Range.Paragraphs(17).Range.Words(3)
- nomPdf = "C:\Users\10012055U\Desktop\Test\Attestation Ligue1 " & nom & prenom & ".pdf"
- ActiveDocument.ExportAsFixedFormat OutputFileName:=nomPdf, ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, _
- OptimizeFor:=wdExportOptimizeForPrint, From:=i, To:=i, Range:=wdExportFromTo, _
- Item:=wdExportDocumentContent, IncludeDocProps:=True, _
- CreateBookmarks:=wdExportCreateNoBookmarks
- Next i
- End With
- End Sub
|
Il se peut aussi que nom ou prénom contienne un caractère interdit dans les noms de fichier.
|