vba - I need to create a stopping condition for my program -
i have program highlights words between start , end point , loops through extract find same conditions. program works well, except not stop looping. have break running program stop it. can please me write condition says if end reached , start , end condition don't exist, stop program.
sub somesub1() dim startword string, endword string dim find1strange range, findendrange range dim delrange range, delstartrange range, delendrange range application.screenupdating = false application.displayalerts = false 'setting ranges set find1strange = activedocument.range set findendrange = activedocument.range set delrange = activedocument.range 'set start , end find words here cleanup script startword = "from: yussuf ismail" endword = "kind regards" 'starting find first word find1strange.find .text = startword .replacement.text = "" .forward = true .wrap = wdfindask .format = false .matchcase = false .matchwholeword = false .matchwildcards = false .matchsoundslike = false .matchallwordforms = false 'execute find while .execute 'if found script if .found = true 'setting found range delstartrange set delstartrange = find1strange 'having these selections during testing benificial test script delstartrange.select 'setting findendrange remainder of document form end of startword findendrange.start = delstartrange.end findendrange.end = activedocument.content.end 'having these selections during testing benificial test script findendrange.select 'setting find end word findendrange.find .text = endword .execute 'if found script if .found = true 'setting found range delendrange set delendrange = findendrange 'having these selections during testing benificial test script delendrange.select end if end 'selecting delete range delrange.start = delstartrange.start delrange.end = delendrange.end 'having these selections during testing benificial test script delrange.select delrange.highlightcolorindex = wdpink 'remove comment delete end if 'ending if find1strange .found = true loop 'ending while .execute loop end 'ending find1strange.find statement end sub
it keeps on going because of application.displayalerts = false
this remove "search has reached end of document. want continue searching @ beginning?" message.
if remove application.displayalerts = false
stop @ end of document , message pop up.
also change following in initial find
:
.wrap = wdfindask
to
.wrap = wdfindstop
this not ask question , stop find
.
Comments
Post a Comment