J
James Houston
Using Word 97, I'm trying to insert a page break in a document that uses a
string of "=" characters to indicate the start of a new record. What I want
the macro to do is insert a page break before the "=". Here's the macro:
Sub SetPageBreak()
'
' SetPageBreak Macro
' Macro recorded 06/01/04 by James D. Houston
'
Dim iBreakCount As Integer
Dim iLen As Integer
Dim sText As String
Dim myRange As Range
sText =
"======================================================================"
Set myRange = ActiveDocument.Content
myRange.Start = 0
Do While Not myRange.End
myRange.Find.Execute
findtext:="=================================================================
=====", Forward:=True
iLen = Len(sText)
If myRange.Find.Found = True Then
iBreakCount = iBreakCount + 1
If iBreakCount = 1 Then
'do nothing
Else
With myRange
.Collapse direction:=wdCollapseEnd
.InsertBreak wdPageBreak
End With
End If
Else
MsgBox "Done" & " " & iBreakCount & " orders found"
Exit Sub
End If
Loop
End Sub
if I omit the .Collapse method, the page break overwrites the "=" string.
If I change the direction parameter to wdCollapseStart, it inserts an
infinite number of page breaks. How do I Word to insert the page break
before the string?
Any help would be greatly appriciated.
Best,
Jim
string of "=" characters to indicate the start of a new record. What I want
the macro to do is insert a page break before the "=". Here's the macro:
Sub SetPageBreak()
'
' SetPageBreak Macro
' Macro recorded 06/01/04 by James D. Houston
'
Dim iBreakCount As Integer
Dim iLen As Integer
Dim sText As String
Dim myRange As Range
sText =
"======================================================================"
Set myRange = ActiveDocument.Content
myRange.Start = 0
Do While Not myRange.End
myRange.Find.Execute
findtext:="=================================================================
=====", Forward:=True
iLen = Len(sText)
If myRange.Find.Found = True Then
iBreakCount = iBreakCount + 1
If iBreakCount = 1 Then
'do nothing
Else
With myRange
.Collapse direction:=wdCollapseEnd
.InsertBreak wdPageBreak
End With
End If
Else
MsgBox "Done" & " " & iBreakCount & " orders found"
Exit Sub
End If
Loop
End Sub
if I omit the .Collapse method, the page break overwrites the "=" string.
If I change the direction parameter to wdCollapseStart, it inserts an
infinite number of page breaks. How do I Word to insert the page break
before the string?
Any help would be greatly appriciated.
Best,
Jim