help with macro please

S

simmo

Hi all,

Any help would be appreciated
I am trying to get this macro to run to the end of the word document
then stop.

But it keeps on looping

Without the loop command it will only do what I want once



Do Until Selection.HomeKey

Selection.HomeKey Unit:=wdLine

Selection.Find.ClearFormatting
With Selection.Find
.Text = "FD"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=2
Selection.MoveRight Unit:=wdCharacter, Count:=4, Extend:=wdExtend
Selection.Shading.Texture = wdTextureNone
Selection.Shading.ForegroundPatternColor = wdColorAutomatic
Selection.Shading.BackgroundPatternColor = wdColorLightYellow
Selection.Shading.Texture = wdTextureNone
Selection.Shading.ForegroundPatternColor = wdColorAutomatic
Selection.Shading.BackgroundPatternColor = wdColorLightYellow
Selection.MoveRight Unit:=wdCharacter, Count:=1
End With

Loop

End Sub
 
D

Doug Robbins - Word MVP

Use:

Dim frange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="FD", MatchWildcards:=False,
MatchCase:=True, _
Wrap:=wdFindStop, Forward:=True) = True
Set frange = Selection.Range
frange.Start = frange.Start - 2
frange.Shading.ForegroundPatternColor = wdColorAutomatic
frange.Shading.BackgroundPatternColor = wdColorLightYellow
Selection.Collapse wdCollapseEnd
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top