Word 2007-在文件末尾停止的查找/替换循环 [英] Word 2007 - A Find/Replace loop that stops at the End of File

查看:112
本文介绍了Word 2007-在文件末尾停止的查找/替换循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我显然是新手,这可能是一个错误的提出问题的网站,但是我很拼命:

我有一个查找和替换操作,该操作删除某个字符串的四个实例,然后完整保留一个实例.

我想做的就是整个操作循环,直到文件末尾.

我想出的每个循环都是无限的.在线示例代码似乎不适用于我.例如:

I''m clearly a newbie, and this may be the wrong site to ask a question, but I''m desperate:

I''ve got a Find and replace operation that deletes four instances of a certain string, then leaves one instance intact.

What I''d like to do is have this whole operation loop until the end of the file.

Every loop I come up with turns infinite. Sample code online doesn''t seem to work for me. This, for example:

Do Until ActiveDocument.Bookmarks("\Sel") = _
   ActiveDocument.Bookmarks("\EndOfDoc")

推荐答案

好吧,您可以按照此模式进行操作.您可以添加一个计数器,并在每第五次出现时检查一次.

Well, you can do it in this pattern. You can add a counter and check it for every fifth occurence.

Dim myStoryRange As Microsoft.Office.Interop.Word.Range
For Each myStoryRange In doc.StoryRanges
 With myStoryRange.Find
 .Text = "targetstring"
 .Replacement.Text = ""
 .Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindAsk
 .Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceOne)
End With
Next myStoryRange


这篇关于Word 2007-在文件末尾停止的查找/替换循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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