Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-28-2023, 02:57 AM
vivka vivka is offline help on this Windows 7 64bit help on this Office 2016
Expert
 
Join Date: Jul 2023
Posts: 302
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
Reply



Other Forums: Access Forums

All times are GMT -7. The time now is 10:42 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft