Macro Word et Publipostage

mimeuh Messages postés 1 Date d'inscription   Statut Membre Dernière intervention   -  
 unknown -
Bonjour,

j'ai créé un document par publipostage à partir d'une BDD excel (1 ligne = 1 référence client)
Avec la macro BreakOnSection() suivante, j'ai réussi à couper le document en autant de documents que de lignes (en coupant à chaque section)

Sub BreakOnSection()
' Used to set criteria for moving through the document by section.
Application.Browser.Target = wdBrowseSection

'A mail merge document ends with a section break next page.
'Subtracting one from the section count stop error message.
For i = 1 To ((ActiveDocument.Sections.Count) - 1)

'Note: If a document does not end with a section break,
'substitute the following line of code for the one above:
'For I = 1 To ActiveDocument.Sections.Count

'Select and copy the section text to the clipboard.
ActiveDocument.Bookmarks("\Section").Range.Copy

'Create a new document to paste text from clipboard.
Documents.Add
Selection.Paste

' Removes the break that is copied at the end of the section, if any.
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
ChangeFileOpenDirectory "C:\"
DocNum = DocNum + 1
StrName = RTrim(ActiveDocument.Paragraphs(1).Range.Text)
ActiveDocument.SaveAs FileName:=StrName & ".doc"
' Move the selection to the next section in the document.
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub


Je l'ai modifiée (lignes 25-26) pour que le fichier soit enregistré avec le nom présent sur la première ligne, sauf que la macro prend aussi le saut à la ligne et me signale donc une erreur à l'enregistrement.

Quelqu'un peut me sortir de cette galère ? \o/
Merci !

PS : je travail sous Word 2000 et je suis une débutante en VB !
A voir également:

2 réponses

mimeuh
 
up
0
unknown
 
up
0