Determine Selection Bkmrk Name

J

Jim Dahlstrom

Thanks to any that respond.

Using Word 2002.

In automating the development of documents (i.e.
procurement specifications) a routine has been developed
that allows the "author" to identify (mark) certain
phrases using bookmarks for later reference.

A routine is needed that will load a variable with
the .Name of the bookmark the user's cursor is within.

The following code returns an incorrect result:

BNo = Selection.BookmarkID
Bname = Selection.Bookmarks(BNo).Name

I am certain that the cursor is between the boundaries of
a bookmark. The returned BNo is the ID of a bookmark that
is 10 pages away from the cursor position and Bname indeed
returns the name of that bookmark.

My feeling is that a .Range definition is needed, but have
tried multiple variations (using the VBA help attached to
the Office 2000) without success.

What code can produce the appropriate >Name?
 
P

Peter Hewett

Hi Jim Dahlstrom

Use this:
With Selection.Bookmarks
If .Count = 1 Then
Bname = .Item(1).Name
Else
' Either zero or more than 1 bookmark in selection
End Id
End With

HTH + Cheers - Peter
 
J

Jim Dahlstrom

Peter,

Thanks. It worked like a charm. Sometimes we don't see
the forest for the trees.

A WORD OF APPRECIATION:

I have browsed this set of newsgroups (Word / VBA) for
numerous issues and have found many answers. Your
responses, however, are by far the most useful. You
answer the stated issue in easy to understand terms, often
realize that we may not know how to ask the appropriate
question and then you answer what is probably the real
issue. Please keep it up.

Regards,
Jim D.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top