Log in

View Full Version : macro help please



simmo
10-19-2008, 11:34 AM
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


Thanks

GTO
10-20-2008, 01:19 AM
Hello Simmo,

I'm not much into Word, but Selection may not be ideal, but it is workable. Anyways, no loop is needed.

With Selection
.HomeKey Unit:=wdStory
.Find.ClearFormatting
.Find.Replacement.ClearFormatting
With .Find
.Text = "FD"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
.Find.Execute Replace:=wdReplaceAll
End With

The key is the Replace:=wdReplaceAll

Have a good one,

Mark

simmo
10-20-2008, 09:46 AM
Thank you i will give it a go.

fumei
10-20-2008, 12:49 PM
Perhaps explain precisely what you trying to do.