来自vb.net的单词自动化 [英] word automation from vb.net

查看:72
本文介绍了来自vb.net的单词自动化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个预定义的模板,我正在尝试从vb.net自动化.我有很多书签,大多数书签都具有与表单相同的值,但我意识到书签应该被唯一地替换,我也应该这样做.必须在每个页面上手动搜索某个书签?除非我使用以下语句

wordDocument.Range.GoToNext(Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage)
并替换该页面上的书签,我的程序没有运行.我收到错误消息,指出对象在书签集合中不存在.
由于书签插入到下一页,如果插入时间太长,我遇到了麻烦.
目前,我通过的页面计数为100,并循环遍历所有页面以进行替换,但是还有更好的解决方案吗?

我急需答案,因此将不胜感激.

预先感谢.

I have predefined templates in word which i am trying to automate from vb.net.I have many bookmarks most of which take the same value from form.But I realized that bookmarks should be uniquely name to be replaced.Also do I have to search manually on each page for a certain bookmark?Unless I am using the statement

wordDocument.Range.GoToNext(Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage)
and replacing the bookmark on that page my program is not running.I get the error the referenced object doesn''t exist in the bookmarks collection.
I am having trouble with this as due to long insertions if the bookmark moves on to the next page I am getting an error.
for now I am passing a count of say 100 as the page count and looping through all pages to replace but is there any better solution?

I need the answer urgently so any help would be greatly appreciated.

Thanks in advance.

推荐答案

我还必须在每个页面上手动搜索某个书签吗?

不,你没有.为什么?因为Bookmarks是文档中的集合(无论页数如何)!请,请参阅我对您之前的问题的回答.

要扩大文档中的书签,可以使用For each ... NextDo ... Loop语句.例如:
Also do I have to search manually on each page for a certain bookmark?

No, you don''t. Why? Becouse Bookmarks is the collection in a document (no matter of count of pages)! Please, see my answer to your previus question.

To enumarate bookmarks in the document you can use For each ... Next or Do ... Loop statements. For example:
Dim bkm as Bookmark
For Each bkm in ActiveDocument.Bookmarks
    'do some job with bookmark
Next bkm



您也可以通过其他方式来做到这一点:



You can do it in a different way too:

bkm = ActiveDocument("BookmarkName")
'or
bkm = ActiveDocument(1)


这篇关于来自vb.net的单词自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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