vamshivemula
02-21-2010, 07:27 PM
Hi,
I need a help with VBA code where ONLY one particular color highlighted text is selected (for instance a word highlighted in BRIGHT Green (wdBrightGreen)) and the color is removed for the selected text. I used the below code to remove the highlight which follows after the find code, but the code I used find all the highlighted text irrespective of what color it is:
While Selection.Find.Execute = True
Selection.Range.HighlightColorIndex = wdNoHighlight
Wend
I need this in two ways. First is to select all Bright Green highlighted text and remove the highlight in one instance in whole document and the second is to find one word at time and remove only one time so that I can have proper control. I used the following macro code which does not allow me to select particular color but finds the text whichever is highlighted.
Public Sub callChoice()
If MyFrm.optWord.Value = True Then
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Highlight = True
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Highlight = False
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
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
ElseIf MyFrm.optDoc.Value = True Then
Unload MyFrm
Application.ScreenUpdating = False
Selection.WholeStory
Options.DefaultHighlightColorIndex = wdNoHighlight
Selection.Range.HighlightColorIndex = wdNoHighlight
MsgBox ("All the highlights in the Document are removed")
Selection.HomeKey Unit:=wdStory
Application.ScreenUpdating = True
End If
End Sub
I need a help with VBA code where ONLY one particular color highlighted text is selected (for instance a word highlighted in BRIGHT Green (wdBrightGreen)) and the color is removed for the selected text. I used the below code to remove the highlight which follows after the find code, but the code I used find all the highlighted text irrespective of what color it is:
While Selection.Find.Execute = True
Selection.Range.HighlightColorIndex = wdNoHighlight
Wend
I need this in two ways. First is to select all Bright Green highlighted text and remove the highlight in one instance in whole document and the second is to find one word at time and remove only one time so that I can have proper control. I used the following macro code which does not allow me to select particular color but finds the text whichever is highlighted.
Public Sub callChoice()
If MyFrm.optWord.Value = True Then
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Highlight = True
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Highlight = False
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
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
ElseIf MyFrm.optDoc.Value = True Then
Unload MyFrm
Application.ScreenUpdating = False
Selection.WholeStory
Options.DefaultHighlightColorIndex = wdNoHighlight
Selection.Range.HighlightColorIndex = wdNoHighlight
MsgBox ("All the highlights in the Document are removed")
Selection.HomeKey Unit:=wdStory
Application.ScreenUpdating = True
End If
End Sub