Ms word 2016 – comment vérifier si le texte est déjà mis en surbrillance ou non

Ceci est basé sur le thread Comment sélectionner le texte ALL DELETED (ou ALL ADDED) (changement de piste) dans MS Word 2016

L'utilisateur endrju m'a donné une macro qui mettra en évidence les ajouts et les suppressions dans ms word 2016 en différentes couleurs.

Sub MarkChanges() Dim arev As Revision With ActiveDocument For Each arev In .Revisions If arev.Type = wdRevisionDelete Then arev.Range.HighlightColorIndex = wdYellow ElseIf arev.Type = wdRevisionInsert Then arev.Range.HighlightColorIndex = wdGreen End If Next arev End With End Sub 

J'ai fait quelques changements, et ça fonctionnait bien, alors j'ai remarqué que si le texte est déjà mis en évidence, il changeait la couleur de l'accent même.

Je ne voulais pas que cela se produise, alors j'ai changé la macro à t

 With ActiveDocument For Each arev In .Revisions If arev.Type = wdRevisionInsert Then If arev.Range.HighlightColorIndex = wdNoHighlight Then arev.Range.HighlightColorIndex = wdBrightGreen End If ElseIf arev.Type = wdRevisionDelete Then If arev.Range.HighlightColorIndex = wdNoHighlight Then arev.Range.HighlightColorIndex = wdTurquoise End If End If Next arev End With 

Mais il mettait maintenant en évidence "seulement" le texte qui était déjà mis en évidence, et ne faisait rien avec le texte qui n'était pas souligné. Il s'agissait exactement de l'inverse de la façon dont je voulais que cela fonctionne.

Je ne voulais pas que cela se produise, alors j'ai changé la macro à t

 With ActiveDocument For Each arev In .Revisions If arev.Range.HighlightColorIndex = wdNoHighlight Then If arev.Type = wdRevisionInsert Then arev.Range.HighlightColorIndex = wdBrightGreen End If ElseIf arev.Type = wdRevisionDelete Then If arev.Range.HighlightColorIndex = wdNoHighlight Then arev.Range.HighlightColorIndex = wdTurquoise End If End If Next arev End With 

Même alors, il faisait la même chose que précédemment, c'est-à-dire en faisant exactement ce que je voulais.

Le code ne devrait-il pas

 If arev.Range.HighlightColorIndex = wdNoHighlight Then 

Ne travaillez que sur le texte qui a sélectionné HighlightColorIndex sur wdNoHighlight, ce qui signifie que le texte n'a pas été mis en surbrillance?