1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
Sub DeveloppezLectureDeTousLesMotsElementParElement()
' On va au début du document
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "par_trk" 'Attention, avant on recherchait "par_trk_"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
End With
Selection.Find.Execute
While Selection.Find.Found
aMotRecherche = Selection.Range.Text
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
While Selection.Range.Text = "_"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
aMotRecherche = aMotRecherche + "_" + Selection.Range.Text
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Wend
'Lorsque l'on dans une table dont l'entrée est le mot recherché, Word sélectionne la cellule complète et donc
' le mot que l'on vient d'indexer ==> ça boucle
If (Selection.Range.Tables.Count > 0) And (InStr(Selection.Text, aMotRecherche) > 0) Then
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Else
Selection.MoveLeft Unit:=wdCharacter, Count:=1
End If
'On a trouvé donc on marque l'entrée
ActiveDocument.Indexes.MarkEntry Range:=Selection.Range, Entry:=aMotRecherche, EntryAutoText:=aMotRecherche
'Attention, en cas affichage des caractères masqués les index d'entrées sont affichés
' donc vont être retrouvés par la recherche ==> il faut les passer
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=1
With Selection.Find
.Text = "par_trk" 'Attention, avant on recherchait "par_trk_"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
End With
Selection.Find.Execute
Wend
' On compile alors l'index
With ActiveDocument
.Indexes.Add Range:=Selection.Range, HeadingSeparator:= _
wdHeadingSeparatorNone, Type:=wdIndexIndent, RightAlignPageNumbers:= _
True, NumberOfColumns:=2, AccentedLetters:=False
.Indexes(1).TabLeader = wdTabLeaderDots
End With
End Sub |
Partager