简体   繁体   中英

Sorting word bookmarks by location in vba

I am trying to cycle through the bookmarks in a word document by their location.

yes I have seen this: How to get list of all bookmark-elements from a Word document to an array in order by location: VBA / Word

no it didn't work. and for the life of me I am not sure why this doesn't since it is lifted from a MS support page.

Sub cycleBookmarks()
 ActiveDocument.Bookmarks.DefaultSorting = wdSortByLocation
 Dim bkm As Bookmark
  For Each bkm In ActiveDocument.Bookmarks
  Next bkm
End Sub

Anybody know how to properly cycle through bookmarks by document location? I don't care about headers and footers (though a complete answer would be nice)

According to this MSDN site DefaultSorting property :

Returns or sets the sorting option for bookmark names displayed in the Bookmark dialog box (Insert menu). Read/write WdBookmarkSortBy.

Therefore you need to use @Mana solution from the link you provided in your question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM