I'm wondering how to break a Find loop when the search reaches the end of the document.
Below is code without the break due to reaching the end of the document. Do I need to use some On Error function?
This is VBA in a word document but I believe the Find function works the same in excel.
Thanks,Sub AddPageBreaks() 'Adds Page Breaks where needed '06/22/2010 Application.ScreenUpdating = False Selection.MoveDown Unit:=wdLine, Count:=2 Selection.Find.ClearFormatting With Selection.Find .Text = "FIND ME" .Replacement.Text = ".fe" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Do 'EndofDoc = (Selection.End = ActiveDocument.Content.End - 1) Selection.Find.Execute Selection.MoveUp Unit:=wdLine, Count:=1 Selection.InsertBreak Type:=wdPageBreak Selection.MoveDown Unit:=wdLine, Count:=2 CurPage = Selection.Information(wdActiveEndAdjustedPageNumber) Loop Until CurPage = 100 Application.ScreenUpdating = True End Sub
I'll move this to the Word forum, huh?
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks