Solved

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

786 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