MS Word: Iterate over each element in document's bookmarks list

This is a code share rather than a question.

I had been iterating through bookmarks by incrementing a counter based on bookmarks size

set numOfBookmarks to the number of bookmarks in active document
repeat with i from 1 to numOfBookmarks
   display dialog (name of bookmark i of active document) as string
end repeat

and was wondering if it was possible to iterate directly over elements in the list.

Did a quick Google search and came up with nothing.

Looked at some ‘repeat with…’ examples in the word-2004-applecript-reference guide, tried some things, and found this to work (see next post):

repeat with b in (get bookmarks in active document)
   display dialog (name of b) as string
end repeat

You could probably even do something like this:

repeat with bmrk in the name of the active document's bookmarks
        display dialog bmrk's contents
end repeat
1 Like