我需要为程序创建一个停止条件

编程入门 行业动态 更新时间:2024-10-26 18:23:15
本文介绍了我需要为程序创建一个停止条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个程序,突出显示起点和终点之间的所有单词,并在提取物中循环查找相同的条件.程序运行良好,但不会停止循环.我必须中断正在运行的程序才能停止它.有人可以帮我写一个条件,说是否达到了结束条件,并且开始条件和结束条件不存在,请停止程序.

I have a program that highlights all the words between a start and end point and loops through the extract to find the same conditions. Program works well, except it does not stop looping. I have to break the running program to stop it. can someone please help me write up a condition that says if the end is reached and the start and end condition don't to exist, to stop the program.

Sub SomeSub1() Dim StartWord As String, EndWord As String Dim Find1stRange As range, FindEndRange As range Dim DelRange As range, DelStartRange As range, DelEndRange As range Application.ScreenUpdating = False Application.DisplayAlerts = False 'Setting up the Ranges Set Find1stRange = ActiveDocument.range Set FindEndRange = ActiveDocument.range Set DelRange = ActiveDocument.range 'Set your Start and End Find words here to cleanup the script StartWord = "From: Yussuf Ismail" EndWord = "Kind regards" 'Starting the Find First Word With Find1stRange.Find .Text = StartWord .Replacement.Text = "" .Forward = True .Wrap = wdFindAsk .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False 'Execute the Find Do While .Execute 'If Found then do extra script If .Found = True Then 'Setting the Found range to the DelStartRange Set DelStartRange = Find1stRange 'Having these Selections during testing is benificial to test your script DelStartRange.Select 'Setting the FindEndRange up for the remainder of the document form the end of the StartWord FindEndRange.Start = DelStartRange.End FindEndRange.End = ActiveDocument.Content.End 'Having these Selections during testing is benificial to test your script FindEndRange.Select 'Setting the Find to look for the End Word With FindEndRange.Find .Text = EndWord .Execute 'If Found then do extra script If .Found = True Then 'Setting the Found range to the DelEndRange Set DelEndRange = FindEndRange 'Having these Selections during testing is benificial to test your script DelEndRange.Select End If End With 'Selecting the delete range DelRange.Start = DelStartRange.Start DelRange.End = DelEndRange.End 'Having these Selections during testing is benificial to test your script DelRange.Select DelRange.HighlightColorIndex = wdPink 'Remove comment to actually delete End If 'Ending the If Find1stRange .Found = True Loop 'Ending the Do While .Execute Loop End With 'Ending the Find1stRange.Find With Statement End Sub

推荐答案

由于Application.DisplayAlerts = False

这将删除搜索已到达文档末尾.是否要从头开始继续搜索?"消息.

This will remove the "Search has reached the end of the document. Do you want to continue searching at the beginning?" message.

如果删除Application.DisplayAlerts = False,它将停止在文档末尾,并弹出该消息.

If you remove the Application.DisplayAlerts = False then it will stop at the end of the document and that message will pop up.

还要在初始Find中更改以下内容:

Also change the following in the initial Find:

.Wrap = wdFindAsk

收件人

.Wrap = wdFindStop

然后,它不会问这个问题,而只是停止Find.

this will then not ask the question and just stop the Find.

更多推荐

我需要为程序创建一个停止条件

本文发布于:2023-11-25 07:34:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628877.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:创建一个   条件   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!