问题
I want to fetch all the bookmarks in my Word document, and then push them to an array. The bookmarks must be sorted by their location in document not by name.
ex. here's a list of bookmarks in a document,
[bm_s] (header)
[bm_h] (title)
[bm_a] (footer)
I want the bookmarks to keep their order so that the array will look like as following,
array {bm_s, bm_h, bm_a, }
ex. how it should not look like below,
array {bm_a, bm_h, bm_s, }
I got the fetching of all the bookmarks from document working. I get all the bookmarks in random order when fetching and pushing to the array.
回答1:
Oki, so i figured it out,
Here's how its done if someone else is interested in fetching all of the bookmarks with respect to its location on document.
Dim objDoc As Document
Set objDoc = ActiveDocument
For i = 1 To objDoc.Bookmarks.Count
Debug.Print objDoc.Range.Bookmarks(i) 'here you can change the code to push the bookmarks in an array
Next i
回答2:
In case anyone still wants to know; you can access different parts of a MS Word document, like this:
ActiveDocument.StoryRanges(wdPrimaryHeaderStory).Bookmarks.Count
ActiveDocument.StoryRanges(wdMainTextStory).Bookmarks.Count
ActiveDocument.StoryRanges(wdPrimaryFooterStory).Bookmarks.Count
来源:https://stackoverflow.com/questions/14725395/how-to-get-list-of-all-bookmark-elements-from-a-word-document-to-an-array-in-ord