bookmarkid error

S

Smallweed

When I run the following I get a "requested member of the collection does not
exist" error:

If Selection.BookmarkID <> 0 Then
MsgBox ActiveDocument.Bookmarks(Selection.BookmarkID).Name
End If

It's because the id of the bookmark enclosing my cursor happens to be 13 and
yet the ActiveDocument.Bookmarks.Count is only 11.

How can this be??
 
S

Stefan Blom

Not sure why you are getting an error message, but note that you can use the
following code to return the name of the first bookmark in the selection:

Dim MyBookmark As Bookmark
If Selection.Bookmarks.Count > 0 Then
Set MyBookmark = Selection.Bookmarks(1)
MsgBox MyBookmark.Name
End If
 

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

Top