Thread: [Solved] Code for storing new word
View Single Post
 
Old 02-11-2015, 10:07 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,359
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could use a macro like:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim StrFnd As String
StrFnd = Trim(InputBox("Please input the word to find."))
If StrFnd = "" Then Exit Sub
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = StrFnd
    .Replacement.Text = "^&"
    .Format = True
    .Forward = True
    .Wrap = wdFindContinue
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
  End With
  If .Find.Found = True Then
    .Select
    '.HighlightColorIndex = wdYellow
  Else
    .InsertAfter vbCr & StrFnd
  End If
End With
Application.ScreenUpdating = True
End Sub
As coded, the macro merely selects the work if found. If you really do want to apply a highlight, uncomment the expression '.HighlightColorIndex = wdYellow'.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote