T
TJ
Our mainframe formats some of our reports to have multiple reports in one
file end-to-end. Each report begins with SAM5XXX. I would like to put a
page break at each instance of SAM5. The below macro works, but it puts a
blank page at the beginning of the document, thus the two lines after the
"Loop".
Can anyone suggest how to clean up the code to it does not put a blank page
at the beginning?
Thanks for your help!
Sub SAM5_PageBreak()
'
'
'
With ActiveDocument.Content.Find
.ClearFormatting
Selection.MoveDown Unit:=wdLine, Count:=2
Do While .Execute(FindText:="SAM5", Forward:=True, Format:=False) =True
With Selection.Find
.Forward = True
.ClearFormatting
.MatchWholeWord = False
.MatchCase = False
.Wrap = wdFindContinue
.Execute FindText:="SAM5"
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.InsertBreak Type:=wdPageBreak
Selection.MoveDown Unit:=wdLine, Count:=2
End With
Loop
Selection.HomeKey Unit:=wdStory
Selection.Delete Unit:=wdCharacter, Count:=1
End With
End Sub
file end-to-end. Each report begins with SAM5XXX. I would like to put a
page break at each instance of SAM5. The below macro works, but it puts a
blank page at the beginning of the document, thus the two lines after the
"Loop".
Can anyone suggest how to clean up the code to it does not put a blank page
at the beginning?
Thanks for your help!
Sub SAM5_PageBreak()
'
'
'
With ActiveDocument.Content.Find
.ClearFormatting
Selection.MoveDown Unit:=wdLine, Count:=2
Do While .Execute(FindText:="SAM5", Forward:=True, Format:=False) =True
With Selection.Find
.Forward = True
.ClearFormatting
.MatchWholeWord = False
.MatchCase = False
.Wrap = wdFindContinue
.Execute FindText:="SAM5"
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.InsertBreak Type:=wdPageBreak
Selection.MoveDown Unit:=wdLine, Count:=2
End With
Loop
Selection.HomeKey Unit:=wdStory
Selection.Delete Unit:=wdCharacter, Count:=1
End With
End Sub