Test Doc to replace non numbered paras under numbered paras.docx
Hi, I'm hoping someone can help me with a macro I am trying to create that indents non-numbered paragraphs under Heading 1-7 but ignores if the next paragraph is a heading number, so:
Heading 1 = Body1
Heading 2 = Body2
Heading 3 = Body3
Heading 4 = Body4
Heading 5 = Body5
Heading 6 = Body6
Heading 7 = Body7
So far the code works for Heading 1 but is removing the heading 2 numbering and making those as Body1. I haven't got as far as adding in the other heading/body levels until I can sort out this problem first.
If anyone can advise what I'm missing in the code I would be really grateful.
Thanks, Shelley
Code:
Sub ChangeParasAfterHeading()
Dim para As Paragraph, nextPara As Paragraph, oRng As Range
If Selection.Type = wdSelectionIP Then
MsgBox Prompt:="You have not selected any text!"
Exit Sub
End If
Set oRng = Selection.Range
With oRng
For Each para In oRng.Paragraphs
If para.Style = "Heading 1" Then
Set nextPara = para.Next
If Not nextPara Is Nothing Then
nextPara.Style = "Body1"
Else
If para.Style = "Heading 2" Then
Set nextPara = para.Next
If Not nextPara Is Nothing Then
nextPara.Style = "Body2"
Else
End If
End If
End If
End If
Next
End With
End Sub