Thread: help on this
View Single Post
 
Old 08-28-2023, 02:57 AM
vivka vivka is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Jul 2023
Posts: 293
vivka is on a distinguished road
Default

Hi, try this. First I typed then removed my comments becuase, hopefully, the code is quite simple. Besides, I used selection, which I prefer. If you want to work on the whole doc, press Ctrl+A.
Code:
Sub Paras_Start_Change_1()
'Change the selected paras from Before to After:
'Before:
' <S1>Text
' <S2>Text
' <S3>Text
' <S4>Text
' <S5>Text

'After:
' <S1>Text
' <S1-S2>Text
' <S2-S3>Text
' <S3-S4>Text
' <S4-S5>Text

Dim oSel As range
Dim oPar As Paragraph

    Application.ScreenUpdating = False
    Set oSel = selection.range
    For i = selection.range.Paragraphs.count To 1 Step -1
        Set oPar = oSel.Paragraphs(i)
        oPar.range.Select
        selection.Collapse 1
        selection.MoveUp Unit:=wdParagraph, count:=1
        If selection.Start < oSel.Start Then Exit For
        selection.MoveRight Unit:=wdCharacter, count:=1
        selection.MoveEndUntil Cset:=">"
        selection.Copy
        selection.MoveDown Unit:=wdParagraph, count:=1
        selection.MoveRight Unit:=wdCharacter, count:=1
        selection.PasteAndFormat (wdFormatOriginalFormatting)
        selection.TypeText text:="-"
    Next i
    Application.ScreenUpdating = True
End Sub
Reply With Quote