PDA

View Full Version : [SOLVED:] Finding and highlighting text in a word document



Chunk
08-26-2015, 10:01 AM
To the VBA gods,

I have a userform with 2 option buttons

1 option is to have the prog look for the text "New Install", in a Word doc, then highlight it, then print

The other option is to look for "Install", highlight then print.

The problem I am having is, when "Install" is selected, "Install" and the install part of "New Install" are both highlighted when printed.

I have no problem opening or printing the document, just the highlighting part.

There is probably a simple fix for this that is beyond my reach.

Please, any help you can provide would be greatly appreciated. Thanks in advance.

Chunk

Here is the code I am currently working with:



If optbut_Install = True Then
wrdApp.Selection.Find.ClearFormatting
wrdApp.Selection.Find.Replacement.ClearFormatting
wrdApp.Selection.Find.Replacement.Highlight = True
With wrdApp.Selection.Find
.Text = "Install"
.Replacement.Text = "Install"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wrdApp.Selection.Find.Execute Replace:=wdReplaceAll
wrdApp.Options.DefaultHighlightColorIndex = wdYellow
wrdApp.Selection.Range.HighlightColorIndex = wdYellow
End If

If optbut_Newinstall = True Then
wrdApp.Selection.Find.ClearFormatting
wrdApp.Selection.Find.Replacement.ClearFormatting
wrdApp.Selection.Find.Replacement.Highlight = True
With wrdApp.Selection.Find
.Text = "New Install"
.Replacement.Text = "New Install"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wrdApp.Selection.Find.Execute Replace:=wdReplaceAll
wrdApp.Options.DefaultHighlightColorIndex = wdYellow
wrdApp.Selection.Range.HighlightColorIndex = wdYellow

Chunk
12-27-2016, 06:55 AM
Solution was to reword the wanted "highlighted" text then change with the code.