Quantcast
Channel: Word for Developers forum
Viewing all articles
Browse latest Browse all 4350

Adding body text between two conjugative headings without the body part

$
0
0


I want to write a macro so that whenever it find 2 conjugative headings without the body part then just add a text in the body part of the heading which don’t have body.
Input is:
Heading1
Heading 2
Heading 3
        This is the body part.
Output should be
Heading 1
        Added body text
Heading 2
        Added body text
Heading 3
            This is the body part.
I have used the following code but not working



Sub Test4()
Dim i As Integer
i = ActiveDocument.Sentences.Count
For P = 1 To i
   ptext = ActiveDocument.Sentences(P).Text
If ActiveDocument.Sentences(P).Style = "Heading 1" Then
             If ActiveDocument.Sentences(P + 1).Style = "Heading 1" Then
                        'Selection.InsertParagraph
                        Selection.Start = ActiveDocument.Sentences(P).End
                        Selection.InsertAfter "body" & vbCrLf
                        Selection.Style = wdStyleNormal
                        Selection.Start = ActiveDocument.Sentences(P + 1).End
                        i = i + 1
            End If
    End If
Next
End Sub

Viewing all articles
Browse latest Browse all 4350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>