PDA

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



Chunk
09-10-2015, 11:48 AM
I have a userform (created through excel) that has 2 option buttons

1 option is to have the prog look for the text "New Install", in a Word doc, 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 that I am 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

Thread 53588 is the same. After I posted it I came to the realization it fits better here. Sorry for any inconvenience.

gmaxey
09-10-2015, 04:21 PM
A quick and dirty method is to first change "New Install" to something like "New Gobbledygook" process your Install words the change Gobbledygook back to Install.

Chunk
12-27-2016, 06:53 AM
gmaxey's reply is what I ended up using as a solution.