get bookmark by bookmarkID

A

Adolf Kanigowski

Hello!

is ist possible to get the bookmark by the bookmarkID?

Thanks for all helpers

Adolf :)
 
A

Adolf Kanigowski

activedocument.bookmarks("BookMarkName").select

does not work because
the BookmarkID is a property of the Range or Selection Object
and is not the same as the Index

I search for an aquivalent of this:
Set BM = GetBookmarkByID( sel.BookmarkID ) ' as Bookmark

The Problem is,
the Bookmarks collection is a "real collection" using Index (not ID) or then
name
and the name or the index is unknown.
more than one Bookmarks are possible in a Range or Selection
 
J

JGM

Hi Adolf,

I do not know what you are trying to achieve, but since you know that
BookmarkID is a range or selection property, why don't you define a range
first, and then find the bookmark you want in that range? Other than that, I
am confused by you explanations... You write that since you do not know the
bookmark name or collection index number, you cannot select it, which is
true. So, how does the BookmarkID helps you then? The BookmarkID property
always return the bookmark ordinal (numbered) position in the document,
regardless of the range you define. So a bookmark maybe the first in your
range, but fourth overall in the document, so BookamrkID will return 4.

In any case, if this gives you any ideas, here is some code I quickly put
together:
_______________________________________
Sub Play_With_Bookmark()

Dim MyRange As Range
Dim MyBookmark As Bookmark

Set MyRange = ActiveDocument.Range

If Not MyRange.Bookmarks.Count = 0 Then
MsgBox "There are " & MyRange.Bookmarks.Count & _
" bookmarks in your range."
Else
MsgBox "There are no bookmarks in your range."
End If

For Each MyBookmark In MyRange.Bookmarks
MyBookmark.Select
If Selection.BookmarkID = 1 Then
MsgBox "Bookmark " & Selection.BookmarkID
Else
MsgBox "This is not the first " _
& "bookmark in the document."
End If
Next MyBookmark

End Sub
_______________________________________

HTH
Cheers!
 

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