View Single Post
 
Old 01-28-2022, 10:57 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Do you want the DEFINITION section at the top of page 3? If so simply inserting a page break before the paragraph could do the job -see below.
If this doesn't work for you, can you post the document instead of a screen shot so we can see how it is constructed with regard to styles, page breaks and white space?
Code:
Sub Macro1()
Dim oRng As Range
    Set oRng = ActiveDocument.Range

    With oRng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "DEFINITION"
        .Style = "Heading 1"
        .Replacement.Text = "DEFINITION"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        Do While .Execute
            If ListParaNum(oRng.Paragraphs(1)) = 1 Then
                oRng.Paragraphs(1).Range.InsertBefore Chr(12)
                Exit Do
            End If
        Loop
    End With
End Sub

Private Function ListParaNum(oPara As Paragraph) As String
Dim i As Integer
Dim xRefs As Variant
    xRefs = ActiveDocument.GetCrossReferenceItems(wdRefTypeNumberedItem)
    ListParaNum = 0
    With oPara.Range
        If .ListParagraphs.Count = 0 Then
            GoTo lbl_Exit
        End If
        .Collapse wdCollapseEnd
        On Error Resume Next
        For i = 1 To UBound(xRefs)
            If ActiveDocument.ListParagraphs(i).Range.End = .End Then
                ListParaNum = Val(ActiveDocument.ListParagraphs(i).Range.ListFormat.ListString)
                Exit For
            End If
        Next i
    End With
lbl_Exit:
    Exit Function
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote