D
DJENSE00
Hi everyone...my first foray into this group. Hope someone can help!
I have an .rtf file that I am opening in Word. It is a statistical
output summary and needs a bit of reformatting.
Basically, the end of each intended page has a footer that has a text
string that says "ANOVA Results". After that text string I want to
include a page break. There are anywhere from 1 to 50 such page
breaks that need to be inserted - I do not know ahead of time. Can
someone help me loop through this entire document, searching for this
text string and then inserting a page break. By the way, I have
already figured out how to insert the page break in VBA at the
appropriate place but I simply cannot figure out how to loop through
the entire document looking for each instance of this page footer. My
code currently looks like this:
Sub InsertPageBreaks()
'Find instances of page footers
Do Until ActiveDocument.Bookmarks("\Sel") =
ActiveDocument.Bookmarks("\EndOfDoc")
Selection.Find.ClearFormatting
With Selection.Find
.Text = "* ANOVA with Dunnett's/Dunn's (p <= 0.05)"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found = True Then
'After finding the instance of the search string move down
one line
'Selection.TypeText Text:=" "
Selection.MoveDown Unit:=wdLine, Count:=1
'Set a page break at this point and then delete the next
line which is blank
Selection.InsertBreak Type:=wdPageBreak
Selection.Delete Unit:=wdCharacter, Count:=1
Else
Exit Do
End If
Loop
End Sub
The loop never terminates and I have to break out of it.
Any help would be more than greatly appreciated. Probably a simple
answer for someone who knows more than me - i.e. almost anyone!!!
Thanks!!!!
I have an .rtf file that I am opening in Word. It is a statistical
output summary and needs a bit of reformatting.
Basically, the end of each intended page has a footer that has a text
string that says "ANOVA Results". After that text string I want to
include a page break. There are anywhere from 1 to 50 such page
breaks that need to be inserted - I do not know ahead of time. Can
someone help me loop through this entire document, searching for this
text string and then inserting a page break. By the way, I have
already figured out how to insert the page break in VBA at the
appropriate place but I simply cannot figure out how to loop through
the entire document looking for each instance of this page footer. My
code currently looks like this:
Sub InsertPageBreaks()
'Find instances of page footers
Do Until ActiveDocument.Bookmarks("\Sel") =
ActiveDocument.Bookmarks("\EndOfDoc")
Selection.Find.ClearFormatting
With Selection.Find
.Text = "* ANOVA with Dunnett's/Dunn's (p <= 0.05)"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found = True Then
'After finding the instance of the search string move down
one line
'Selection.TypeText Text:=" "
Selection.MoveDown Unit:=wdLine, Count:=1
'Set a page break at this point and then delete the next
line which is blank
Selection.InsertBreak Type:=wdPageBreak
Selection.Delete Unit:=wdCharacter, Count:=1
Else
Exit Do
End If
Loop
End Sub
The loop never terminates and I have to break out of it.
Any help would be more than greatly appreciated. Probably a simple
answer for someone who knows more than me - i.e. almost anyone!!!
Thanks!!!!