Solved

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

Posted on 2014-03-06
2
719 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
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…

630 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