OVH Cloud OVH Cloud

macro surlignage

4 réponses
Avatar
PierreAlain
Bonjour,

je cherche à faire une macro qui :

1) détecte un mot particulier ( en l'occurence "function" )
2) surligne en jaune le paragraphe concerné.

J'ai fait pas mal de tentatives, aucune concluente.

--

Pierre Alain

webmaster@lifnet.org

4 réponses

Avatar
AB
Bonjour,
Essaie ça (il y a sans doute plus élégant, mais ça marche) :
AB

Selection.HomeKey
With Selection.Find
.Forward = True
.ClearFormatting
.MatchWholeWord = True
.MatchCase = False
.Wrap = wdFindContinue
.Execute FindText:="function"
Selection.Extend
Selection.Extend
Selection.Extend
Selection.Extend
Options.DefaultHighlightColorIndex = wdYellow
Selection.Range.HighlightColorIndex = wdYellow
End With
End Sub



PierreAlain wrote:
|| Bonjour,
||
|| je cherche à faire une macro qui :
||
|| 1) détecte un mot particulier ( en l'occurence "function" )
|| 2) surligne en jaune le paragraphe concerné.
||
|| J'ai fait pas mal de tentatives, aucune concluente.
||
|| --
||
|| Pierre Alain
||
||
Avatar
Guy Moncomble
Bonjour à tous,
dans le message ,

Oui, et l'on tient compte du fait que function peut avoir une capitale
majuscule :


Public Sub toto()
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.MatchWildcards = True
.Text = "[F,f]unction"
While .Execute
Selection.Paragraphs(1).Range.Select
Selection.Range.HighlightColorIndex = wdYellow
Selection.Collapse wdCollapseEnd
Wend
End With
End Sub

--
A+

GMO MVP WORD
Avatar
AB
Ah, merci Guy !
D'autant qu'à la réflexion, je pense que mon brouillon de macro ne
fonctionne qu'une fois.
Ca m'apprendra à répondre trop vite :)
A+
André


Guy Moncomble wrote:
|| Bonjour à tous,
|| dans le message ,
||
|| Oui, et l'on tient compte du fait que function peut avoir une
|| capitale majuscule :
||
||
|| Public Sub toto()
|| Selection.HomeKey Unit:=wdStory
|| Selection.Find.ClearFormatting
|| Selection.Find.Replacement.ClearFormatting
|| With Selection.Find
|| .MatchWildcards = True
|| .Text = "[F,f]unction"
|| While .Execute
|| Selection.Paragraphs(1).Range.Select
|| Selection.Range.HighlightColorIndex = wdYellow
|| Selection.Collapse wdCollapseEnd
|| Wend
|| End With
|| End Sub
||
|| --
|| A+
||
|| GMO MVP WORD
Avatar
PierreAlain
Un grand merci à tous les deux.

Ca ressemble plus ou moins à ce que j'avais essayer, mais la votre a un très
gros avantage : ELLE MARCHE :-)


--

Pierre Alain