I am working on a macro to run through a word document and find pages with the title "service team". The program that puts together the document is inserting multiples of this page. (I know the easy thing would be to fix the program, however they have no intentions of fixing this problem. ) I need to keep the first and get rid of all others. Each page is separated by a section break, next page.
Below is what I have so far in my VBA but I need a little assistance. I have it finding the second instance and deleting out 33 lines in the word document, but what would be really neat is if it could delete out everything from the title to the section break, including the section break.
[vba]Sub Macro2()
Selection.HomeKey unit:=wdStory
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="3"
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Service Team"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Find.Execute
If Selection.Find.Found Then
Selection.MoveDown unit:=wdParagraph, Count:=33, Extend:=wdExtend
Selection.Delete unit:=wdCharacter, Count:=1
Else
Selection.HomeKey unit:=wdStory
End If
End Sub
[/vba]
I know that I need to set up the loop to run through and find any of the other occurrances as well.
Thanks for your help with this.
Jake