How to find add a bookmark to a text string in MS Word using vba

I want to find a word ("theText") in a document and assign a bookmark ("theBkMark") to it. What is the code to achieve that.
LVL 16
SheilsAsked:
Who is Participating?
 
GrahamSkanConnect With a Mentor RetiredCommented:
This should find the first occurrence of the word and bookmark it
Sub FindAndBookmark()
Dim rng As Range
Set rng = ActiveDocument.Range
With rng.Find
    .Text = "theText"
    .MatchWholeWord = True
    If .Execute() Then
        ActiveDocument.Bookmarks.Add "theBkMark", rng
    End If
End With
End Sub

Open in new window

0
 
SheilsAuthor Commented:
Perfect!
0
All Courses

From novice to tech pro — start learning today.