根据节号表示的位置以编程方式生成书签
我有一个 HTML 页面,其中包含链接,单击该链接可打开 Word 文档中的特定书签。 我正在处理一个现有的 Word 2003 文档,没有预先存在的书签。 我想使用宏或 VBA 脚本将书签添加到所有节号标题位置。 例子
3.1.4.2 这里
东西
3.1.4.2.1 又来了
更多内容
3.1.4.2.1.1 又来了
更多内容
3.1.4.2.2 又来了又来了
还有更多东西
我想为所有以 XXX 开头的行添加书签。 具有标准的名称格式。
示例(使用上面作为参考)
3.1.4.2 HERE 行将有一个名为 M_3_1_4_2 的书签
3.1.4.2.1 这里又会有一个名为 M_3_1_4_2_1
等
的书签。我的问题是我需要采取什么 VBA 脚本或宏方法才能实现这一点。
I have an HTML page with links that when clicked open to a specific bookmark in a word document. I am working with an existing word 2003 document with no preexisting bookmarks. I want to add bookmarks to all section number header locations using a macro or a VBA script. Example
3.1.4.2 HERE
STUFF
3.1.4.2.1 Here again
MORE STUFF
3.1.4.2.1.1 Here again again
EVEN MORE STUFF
3.1.4.2.2 Here again again again
LOTS MORE STUFF
I want to bookmark all the lines that start with X.X.X...
with a standard format for the name.
Example (using above as reference)
3.1.4.2 HERE line would have a book mark named M_3_1_4_2
3.1.4.2.1 Here again would have a book mark named M_3_1_4_2_1
etc.
My question is what approach with a VBA script or a macro would I need to take that would make this happen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您已经有了范围对象,那么添加书签就很容易了。
确定范围通常是一项艰巨的任务。
现在你说这些是节标题。 它们是实际的单词节标题吗? 它们是否以某种样式分隔? 它们是在文档正文中还是页眉中?
您可以像这样循环浏览文档的各个部分,并将范围设置为该部分的开头。
现在,如果它们不是实际的部分,您通常会希望使用 Find 对象在文档中查找某些内容并循环遍历所有此类项目。 这里的技巧是知道要搜索什么。 下面是一个循环示例。
如需更多 Word vba 帮助,您可以访问此处的 Word MVP 网站:http://word.mvps.org
Adding a bookmark is easy enough if you have the range object already.
Getting the range is often the difficult task.
Now you said these were section headers. Are they actual word section headers? Are they delimited with a certain style? Are they in the body of the document or in page headers?
You can cycle through the sections of a document like this and set a range to the start of the section.
Now if they aren't actual sections, you'll often want to use the Find object to find something in the document and loop through all such items. The trick here is to know what to search for. An example loop is below.
For more word vba help, you can vist the word MVPs site here: http://word.mvps.org