Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 01-28-2022, 10:57 PM
gmayor's Avatar
gmayor gmayor is offline How to move Section 1.0 (Heading 1) into third page in vba word Windows 10 How to move Section 1.0 (Heading 1) into third page in vba word 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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to move Section 1.0 (Heading 1) into third page in vba word Word 2007, cannot insert Section Break (Continuous), only Section Break (Next Page) btse1 Word 3 11-01-2018 09:23 AM
How to move Section 1.0 (Heading 1) into third page in vba word Restarting page numbering only if Section begins with Heading 1 kaurp Word VBA 5 11-02-2017 04:36 AM
How to move Section 1.0 (Heading 1) into third page in vba word Changing a Section Heading to an Appendix Heading stardazy Word 2 11-24-2015 01:04 PM
Cross Reference Heading Number with the word "Section" included bblouin Word 5 12-20-2012 05:27 PM
Prefixing heading numbers with custom letters, varying by section, in Microsoft Word? JoelMarcey Word 0 07-23-2011 08:51 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:58 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft