I need to prepend "*" to the searched word in a table. If the word is found outside a table then this is ignored, i.e. no changes.
I am doing this as follows but is there a better way of doing it? It seems rather clumsy to me.
Code: Select all
Private Function PrependStar2String(Str As String)
Dim selEnd As Long
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = Str
.Replacement.Text = "*" + Str
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
While (Selection.Find.Execute)
If (Selection.Information(wdWithInTable)) Then
selEnd = Selection.Range.End
Selection.Range.Text = "*" + Selection.Range.Text
Selection.Start = selEnd + 1
End If
Wend
End Function
Robie