A family of Microsoft word processing software products for creating web, email, and print documents.
Hello Steve8d,
I'm Shalom and I'd happily help you with your question. In this forum, we are Microsoft consumers just like yourself.
From your code, it seems like you’re trying to loop through a document and insert page breaks at certain points based on some criteria. However, your current loop only runs three times (For i = 1 To 3). If you want to loop through up to 30 pages, you should adjust this to For i = 1 To 30.
Here’s how you might modify your code:
Sub Australia_PageBreaks() Dim i As Integer Dim searchText As String Dim found As Boolean
For i = 1 To 30 searchText = "<" & i & " " found = False
Selection.MoveDown Unit:=wdLine, Count:=3
Selection.Find.ClearFormatting
With Selection.Find
.Text = searchText
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
found = Selection.Find.Execute
If found Then
Selection.HomeKey Unit:=wdLine
Selection.InsertBreak Type:=wdPageBreak
Selection.TypeParagraph
End If
Next i
End Sub
This code will loop through each page in your document (up to 30 pages), and if it finds the specified text, it will insert a page break and a new paragraph at that location.
Please replace 30 with the actual number of pages you want to loop through.
Best Regards, Shalom
Give back to the community. Help the next person with this problem by indicating whether this answer solved your problem. Click Yes or No at the bottom.