J
jw
Word 2003 sp2
I want to return the name of the bookmark preceding the cursor. By
analogy with the second example in the VBA Help file entitled
"PreviousBookmarkID property", I wrote the following preliminary
code:
Dim xBookmarkNumber As Long
xBookmarkNumber = Selection.PreviousBookmarkID
MsgBox xBookmarkNumber
MsgBox ActiveDocument.Bookmarks(xBookmarkNumber).Name
When I tested this code by placing the cursor after the first bookmark
in the document, xBookmarkNumber was identified correctly as 1.
However, the name returned by
ActiveDocument.Bookmarks(xBookmarkNumber).Name was that of a different
bookmark. I finally figured out that the name being returned was the
name of the first bookmark IF THE BOOKMARKS ARE SORTED BY NAME!!!
Can anybody tell me how to retrieve the name of the previous bookmark?
Thanks.
PS: I realize that the following code will retrieve the name:
MsgBox Selection.Bookmarks(1).Name
However, this requires that you select text either surrounding a
placeholder bookmark or within an enclosure bookmark, which I don't
want to have to take the trouble to do. (And in any case, the code
provided in the Help file doesn't work properly!)
I want to return the name of the bookmark preceding the cursor. By
analogy with the second example in the VBA Help file entitled
"PreviousBookmarkID property", I wrote the following preliminary
code:
Dim xBookmarkNumber As Long
xBookmarkNumber = Selection.PreviousBookmarkID
MsgBox xBookmarkNumber
MsgBox ActiveDocument.Bookmarks(xBookmarkNumber).Name
When I tested this code by placing the cursor after the first bookmark
in the document, xBookmarkNumber was identified correctly as 1.
However, the name returned by
ActiveDocument.Bookmarks(xBookmarkNumber).Name was that of a different
bookmark. I finally figured out that the name being returned was the
name of the first bookmark IF THE BOOKMARKS ARE SORTED BY NAME!!!
Can anybody tell me how to retrieve the name of the previous bookmark?
Thanks.
PS: I realize that the following code will retrieve the name:
MsgBox Selection.Bookmarks(1).Name
However, this requires that you select text either surrounding a
placeholder bookmark or within an enclosure bookmark, which I don't
want to have to take the trouble to do. (And in any case, the code
provided in the Help file doesn't work properly!)