Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Red Text in word 1

Status
Not open for further replies.

guitardave78

Programmer
Sep 5, 2001
1,294
0
0
GB
Sorry to break protocol and submit this question in two forums but i am not sure which one to go to

I need to select all text in a word doctment that is red and then paste it into a new document. any ideas :)
 
You would have to program this in VBA. Use the following functions:

Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorDarkRed
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Copy
Selection.EndKey Unit:=wdLine
Selection.EndKey Unit:=wdLine
Selection.EndKey Unit:=wdStory


With this code you find the first red text, select the string and copy it to memory. From here you can work with it. You repeat this till you reach the end of the document with a loop.

Good luck,

Nils Bevaart
 
i used
Sub Macro2()
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorAutomatic
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.WholeStory
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Copy

Documents.Add Template:= _
"C:\WINDOWS\Profiles\amarczewski\Application Data\Microsoft\Templates\Normal.dot" _
, NewTemplate:=False, DocumentType:=0

Selection.Paste
Selection.WholeStory
Selection.Font.Color = wdColorAutomatic
Selection.EndKey


End Sub

then i just undo on the original doc :)

is there a eay to go back to the original doc and then run an undo?
 
found it out the code now reads

Sub Macro2()
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorAutomatic
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.WholeStory
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Copy
ActiveDocument.undo

Documents.Add Template:= _
"C:\WINDOWS\Profiles\amarczewski\Application Data\Microsoft\Templates\Normal.dot" _
, NewTemplate:=False, DocumentType:=0

Selection.Paste
Selection.WholeStory
Selection.Font.Color = wdColorAutomatic
Selection.EndKey


End Sub
 
Actually you don't have to do anything in VBA. All you have to do is go to 'Find and Replace' in Word then click the 'More' button. Select the 'Format' button and click 'Font'. Choose red as font color and click OK. Then check the box that says 'Highlight all items found in: Main Document'. Click 'Find all' and it will select all text in red. Copy and paste into your new document.
 
Thanks thats great !!! have recorded a macro on it ! have a star :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top