Thread: [Solved] Reverse Paragraph List Macro
View Single Post
 
Old 08-14-2021, 02:03 AM
Sark Sark is offline Windows XP Office 2003
Novice
 
Join Date: Apr 2017
Posts: 25
Sark is on a distinguished road
Default Reverse Paragraph List Macro

Hi all.

I found the macro below to reverses the order of a text (paragraph) list. This works just fine, but affects the entire document.
How could I change this to apply the effect to just selected lines.

I've created a few macros in the past for an old version of CorelDraw I used to use, but the various syntex I've tried don't work with Word. Any advice would be appreciated.

Mark

Code:
Sub ReverseOrderOfParagraphs()
    Dim tmpTable As Table
    Dim rg As Range
   
    Set tmpTable = ActiveDocument.Range.ConvertToTable(Separator:=wdSeparateByParagraphs)
    With tmpTable
        .Columns.Add BeforeColumn:=.Columns(1)
       
        Set rg = .Cell(1, 1).Range
        rg.End = rg.End - 1
        rg.Fields.Add Range:=rg, Type:=wdFieldSequence, Text:="a"
        rg.Cells(1).Range.Copy
       
        .Columns(1).Select
        Selection.Paste
        Selection.Fields.Update
       
        .Sort ExcludeHeader:=False, FieldNumber:=1, SortOrder:=wdSortOrderDescending
       
        .Columns(1).Delete
       
        .ConvertToText
    End With
End Sub
Reply With Quote