Solved

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

Posted on 2014-03-06
2
588 Views
Last Modified: 2014-03-06
I want to find a word ("theText") in a document and assign a bookmark ("theBkMark") to it. What is the code to achieve that.
0
Comment
Question by:Sheils
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 39909386
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
 
LVL 16

Author Closing Comment

by:Sheils
ID: 39909518
Perfect!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now