View Single Post
 
Old 03-11-2022, 06:26 AM
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

The following should work, based on your example:
Code:
Sub Macro1()
Dim oRng As Range
Dim oPara As Paragraph
Dim i As Integer
    If Len(Selection.Range) = 0 Then
        MsgBox "Nothing selected", vbCritical
        Exit Sub
    End If
    For i = Selection.Paragraphs.Count To 1 Step -1
        Set oPara = ActiveDocument.Paragraphs(i)
        If oPara.Range.Style Like "Heading #" Then
            Set oRng = oPara.Range
            oRng.Collapse 0
            oRng.MoveEndUntil Chr(9)
            oRng.End = oRng.End + 1
            oRng.Collapse 0
            oRng.Text = vbCr
            Set oRng = oRng.Next.Paragraphs(1).Range
            oRng.Style = "Normal"
        End If
    Next i
lbl_Exit:
    Set oPara = Nothing
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
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