Solved MS Word Loop macro until end of document

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

kimraven

Thread Starter
Joined
Oct 20, 2014
Messages
20
Hi. Need help on this. I'm trying to loop this macro until end of document, or until no auto 'work' text is found. Macro should search all 'work' texts and extends it until the next ), then mark them red, then repeat until end of document.

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorAutomatic
With Selection.Find
.Text = "work"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection
.StartIsActive = False
.Extend Character:=")"
End With
Selection.Font.Color = wdColorRed

Also, can .Extend Character:=")" have a condition too? Like, execute only if ) is auto. I noticed that it will extend even if ) is already marked red.

Thanks!
 

Cookiegal

Karen
Administrator
Malware Specialist Coordinator
Joined
Aug 27, 2003
Messages
117,055
It would be helpful if you'd post the solution please.
 

kimraven

Thread Starter
Joined
Oct 20, 2014
Messages
20
Of course, Cookiegal.

Selection.HomeKey Unit:=wdStory
Do While Selection.Find.Execute = True
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorAutomatic
With Selection.Find
.Text = "work"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
With Selection
.StartIsActive = False
.Extend Character:=")"
End With
Selection.Font.Color = wdColorRed
End With
Loop
End Sub
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top