Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make this macro loop #2

Status
Not open for further replies.

tombaraider

Technical User
Feb 20, 2004
20
US
Can someone please tell me what needs to be added to this macro to make it loop til the end of any document I run it in? Thanks.

Selection.Find.ClearFormatting
With Selection.Find
.Text = "REPORT"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.EndKey Unit:=wdLine
Selection.InsertBreak Type:=wdPageBreak
End Sub
 
I am not a 100% certain, but don't you just need to do a selection.findnext (I believe that is the correct syntax).
 
Apart from inserting a carriage return between the page break and the word 'report' I don't see how this differs from your previous request, and it still does not require you to implement a loop. Pretty much exactly the same code as previously provided works (again this is an example,rather than a fully worked solution):

Code:
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    
    With Selection.Find
        .Text = "Report"
        .Replacement.Text = "^m^p^pReport"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top