Andrew said:
Given an instance of Microsoft.Office.Tools.Word.Bookmark, is there a
way to determine any surrounding bookmarks? I want to know all the
bookmarks that contain the range of a given bookmark.
Thoughts?
Use the InRange function like this, as you iterate through the Bookmarks
collection:
Dim firstBk As Bookmark, tryBk As Bookmark
Set firstBk = ActiveDocument.Bookmarks("bk3")
For Each tryBk In ActiveDocument.Bookmarks
If firstBk.Range.InRange(tryBk.Range) _
And (firstBk.Name <> tryBk.Name) Then
MsgBox firstBk.Name & " is inside " & tryBk.Name
End If
Next tryBk
Note that bookmarks that only partly overlap won't pass the test. That is,
if you have the sentence "The quick brown fox jumps over the lazy dog",
where bk1 covers "quick brown fox" and bk3 covers "fox jumps", then bk3
won't be considered to be inside bk1.