Closed studermartin closed 5 years ago
Sub FixSchusterjunge() Dim curPar As Paragraph Dim lastPar As Paragraph Dim firstParagraphInArticle As Paragraph Dim curArticle As Paragraph Dim curChapter As Paragraph Dim countParagraphsInArticle As Integer Dim pageChapter As Integer Dim pageArticle As Integer Dim pageFirstParagraph As Integer Dim pageSecondParagraph As Integer
pageFirstParagraph = 0
pageSecondParagraph = 0
For Each curPar In ActiveDocument.Sections(4).Range.Paragraphs
Dim curParText As String
' Debug.Print (curPar.Range.Information(wdActiveEndAdjustedPageNumber))
' Debug.Print (curPar.Range.text)
If curPar.style = "Überschrift 1" Then
' ToDo
End If
If curPar.style = "Überschrift 2" Then
If (pageSecondParagraph > pageFirstParagraph) Then
Debug.Print ("Schusterjunge")
' Debug.Print (firstParagraphInArticle.Range.text)
Debug.Print (curArticle.Range.text)
' curArticle.Range.InsertBefore ("X")
curArticle.Range.Select
Selection.ParagraphFormat.PageBreakBefore = True
' Dim rr As Range
' Set rr = curArticle.Range
' rr.ParagraphStyle.
' Selection.Collapse (wdCollapseStart)
' Call Selection.MoveLeft(wdCharacter, 1, wdMove)
' rr.Collapse (wdCollapseStart)
' rr.InsertBefore ("X")
' Selection.SetRange (rr)
' rr.InsertBreak (wdPageBreak)
' curArticle.Range.Collapse(wdCollapseStart).InsertBreak (wdPageBreak)
End If
Set curArticle = curPar
pageArticle = curPar.Range.Information(wdActiveEndAdjustedPageNumber)
pageFirstParagraph = 0
pageSecondParagraph = 0
countParagraphsInArticle = 0
Set firstParagraphInArticle = Nothing
End If
If curPar.style = "Scroll List Number" Or curPar.style = "Standard" Then
countParagraphsInArticle = countParagraphsInArticle + 1
If firstParagraphInArticle Is Nothing Then
Set firstParagraphInArticle = curPar
pageFirstParagraph = curPar.Range.Information(wdActiveEndAdjustedPageNumber)
If (pageArticle < pageFirstParagraph) Then
curArticle.Range.Select
Selection.ParagraphFormat.PageBreakBefore = True
Debug.Print ("y3s")
End If
Else
If (countParagraphsInArticle = 2) Then
pageSecondParagraph = curPar.Range.Information(wdActiveEndAdjustedPageNumber)
End If
End If
End If
Set lastPar = curPar
Next
End Sub
The settings keep paragraph together may generate the effect that the article stays on the previous page, the rest on the next.