I have run into a snag in my VBA solution.
I am checking all endNotes in each bookmark before I delete the bookmark, and relinking, which works fine for the first cross-reference, but I have problems if there are multiples. I have tracked it down to an issue with getting the EndNotes in a bookmark. Here's a snippet of code I am using:
Code:
Dim noteCount as integer
Dim eNote as EndNote
noteCount = oBookmark.Range.EndNotes.Count
Debug.Print "Bookmark " & oBookmark.name & " has " & CStr(noteCount) & " EndNotes."
if (noteCount > 0) Then
For Each eNote in oBookmark.Range.Endnotes
Debug.Print "EndNote #" & eNote.index
Next eNote
end if
When I run this on one of the bookmarks I need to delete, I get the correct NoteCount (e.g. 7), but the loop runs through
ALL of the EndNotes in the document (e.g. I get 42 lines of 'EndNote #X')
Is this a bug, the fact that oBookmark.Range.EndNotes.Count lists 7, but when I loop through the oBookmark.Range.EndNotes collection, I get 42; or is there an error in my code? If this is a bug, is there something I can do to work around this? I haven't tried it yet, but would it be worthwhile to check
eNote.Range.Bookmarks or
eNote.Range.BookmarkID to verify that the EndNote belongs to the current bookmark (assuming this will work)?
EDIT: I'm getting a '0' for both the BookMarkID & Bookmarks.Count
I'm running Word 2007 (which is the same version our client will be using), if that matters.