Thread: [Solved] Do Loop bug
View Single Post
 
Old 07-21-2017, 11:29 PM
donlincolnmsof donlincolnmsof is offline Windows 7 64bit Office 2003
Advanced Beginner
 
Join Date: Oct 2011
Posts: 36
donlincolnmsof is on a distinguished road
Default Do Loop bug

Hello

I have the following do loop, it processes all the data, but its crashed ON SELECTION.CUT ALMOST AT THE END OF THE LOOP.

A bit i understand there has to be some sort of check for terminate the do loop.

Any help will be appreciated.

Thanks.



Do

Selection.Find.ClearFormatting
With Selection.Find
.Text = "Add to watchlist"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Cut
Windows(1).Activate
Selection.Paste
Selection.TypeText Text:=vbTab
Selection.TypeParagraph
Windows(2).Activate

Loop Until Selection.Find.Found = False


Selection.HomeKey Unit:=wdStory
Windows(1).Activate
Selection.HomeKey Unit:=wdStory
Windows(2).Activate
Selection.HomeKey Unit:=wdStory

Do


Selection.Find.ClearFormatting
With Selection.Find
.Text = "TOTAL REVENUE"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Cut
Windows(1).Activate
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=vbTab
Selection.Paste
Selection.TypeParagraph
Selection.Delete Unit:=wdCharacter, Count:=1
Windows(2).Activate


Loop Until Selection.Find.Found = False
Reply With Quote