![]() |
|
#2
|
||||
|
||||
|
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 |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Word 2007, cannot insert Section Break (Continuous), only Section Break (Next Page)
|
btse1 | Word | 3 | 11-01-2018 09:23 AM |
Restarting page numbering only if Section begins with Heading 1
|
kaurp | Word VBA | 5 | 11-02-2017 04:36 AM |
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 |