Solved

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

Posted on 2014-03-06
2
693 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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