Hi ,
The code you posted is not capable of highlighting anything, regardless of whether you use a MACROBUTTON. Also, docx files can't be saved with macros. Based on what you posted, the following should do what you want - in a docm file.
Sub Wordhighlighter()
Dim MyInput As String, i As Long
MyInput = InputBox("Please enter the words which you want to highlight" _
& vbCr & "as a comma-separated list.")
With ActiveDocument.Range.Find
.ClearFormatting
With .Replacement
.Text = "^&"
.ClearFormatting
.Highlight = False
With .Font
.Italic = True
.Color = wdColorRed
.Bold = True
End With
End With
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
For i = 0 To UBound(Split(MyInput, ","))
.Text = Trim(Split(MyInput, ",")(i))
.Execute Replace:=wdReplaceAll
Next
End With
End Sub
PS: When posting code, please use the code tags. They're on the menu.
Bookmarks