Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

VBA Word : sélection jusqu'à un "texte"

Aucune réponse
Avatar
Cain84
Bonjour à tous,
Je réalise un publipostage sous word. Une fois le publipostage terminé j'essaye de séparer le fichier créer en différents sous fichiers. J'ai besoin de séparer le "e;gros fichier"e; en différents petits fichiers (fichier1, fichier2 etc). Pour le moment j'ai un code qui marche mais qui ne me satisfait pas ... Le voici :
'--------------
Sub SéparationCA()
Dim NomDeMonFichier()
r = ActiveDocument.Sections.Count

For i = 1 To r - 1
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=i, Name:="e;"e;
Selection.MoveRight Unit:=wdSentence, Count:=1, Extend:=wdExtend
ReDim Preserve NomDeMonFichier(i)
NomDeMonFichier(i) = Selection
Next i
For i = 1 To r - 1
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=i, Name:="e;"e;
Selection.MoveDown Unit:=wdParagraph, Count:=38, Extend:=wdExtend
Selection.Copy
Documents.Add
Selection.PasteAndFormat (wdPasteDefault)
ChangeFileOpenDirectory "e;C:UsersAndrea.SIMEONDesktopVBABaseTest"e;
ActiveDocument.SaveAs FileName:="e;CA "e; & NomDeMonFichier(i) & "e;.doc"e;
s = DoEvents
ActiveDocument.Close
s = DoEvents
Next i
End Sub
'--------------
J'aimerais savoir s'il est possible de réaliser une sélection mais jusqu'à un texte. Par exemple lorsque word rencontre le texte "e;A bientôt"e; la sélection se termine. Pour ca il faudrait remplacer la ligne :
Selection.MoveDown Unit:=wdParagraph, Count:=38, Extend:=wdExtend

Malheureusement je n'y parviens pas ! Si quelqu'un connait la solution je vous en serais reconnaissant ! :)

Réponses