如何按位置顺序从Word文档到数组获取所有书签元素的列表:VBA/Word [英] How to get list of all bookmark-elements from a Word document to an array in order by location: VBA / Word

查看:412
本文介绍了如何按位置顺序从Word文档到数组获取所有书签元素的列表:VBA/Word的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取Word文档中的所有书签,然后将它们推到数组中.书签必须按其在文档中的位置而不是名称进行排序.

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.

推荐答案

好吧,所以我想通了,

如果其他人有兴趣获取有关其在文档中位置的所有书签,这是完成的操作.

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

这篇关于如何按位置顺序从Word文档到数组获取所有书签元素的列表:VBA/Word的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆