Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 08-01-2018, 11:59 PM
moorea21 moorea21 is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jun 2018
Posts: 6
moorea21 is on a distinguished road
Default reverse order of paragraphs, word 2010

I've been trying to do something that i supposed to be very simple, that is, simply to reverse the order of paragraphs in a very long (150,000 line) .rtf document. If I selesct number/descending in home/paragraph/sort, I end up with what looks to be random garbage; in the sample below, line order (note, not the numbers themselves) that started 1,2,3,4,5,6,7,8,9,10, 11 becomes line order 3,4,2,5,6,7,8,9,10,11,1:


1. A yeah, I damaged mine while reversing... Felt like a right idiot ¨ ¨ Jan 11, 2015 3:28pm
2. B I expect Iíll wreck it! ¨ ¨ Jan 11, 2015 12:06pm
3. B Thatís not going to happen today ¨ ¨ Jan 11, 2015 12:05pm
4. A Just thought, if youíre not setting out too early, can you drop in before you set off? ¨ ¨ Jan 11, 2015 9:38am
5. A bye! ¨ ¨ Jan 11, 2015 8:35am
6. A yes, go to work! ¨ ¨ Jan 11, 2015 8:35am
7. B Gotta go to work!¨ ¨ Jan 11, 2015 8:35am
8. A thats a bit over the top! ¨ ¨ Jan 11, 2015 8:35am
9. A blimey! ¨ ¨ Jan 11, 2015 8:35am
10. B I bought the one with all the options! ¨ ¨ Jan 11, 2015 8:35am
11. A Did you get the cheap one in the end? ¨ ¨ Jan 11, 2015 8:35am


becomes


1. A Did you get the cheap one in the end? ¨ ¨ Jan 11, 2015 8:35am
2. B Thatís not going to happen today ¨ ¨ Jan 11, 2015 12:05pm
3. A yeah, I damaged mine while reversing... Felt like a right idiot ¨ ¨ Jan 11, 2015 3:28pm
4. B I expect Iíll wreck it! ¨ ¨ Jan 11, 2015 12:06pm
5. A Just thought, if youíre not setting out too early, can you drop in before you set off? ¨ ¨ Jan 11, 2015 9:38am
6. A bye! ¨ ¨ Jan 11, 2015 8:35am
7. A yes, go to work! ¨ ¨ Jan 11, 2015 8:35am
8. B Gotta go to work!¨ ¨ Jan 11, 2015 8:35am
9. A thats a bit over the top! ¨ ¨ Jan 11, 2015 8:35am
10. A blimey! ¨ ¨ Jan 11, 2015 8:35am
11. B I bought the one with all the options! ¨ ¨ Jan 11, 2015 8:35am






obviously, waht I wanted was line order, 11,10,9,8,7,6,5,4,3,2,1


Will I need a macro to acheive this?


If so, is there one 'pinned' somewheere on this forum that does this? It seems like such a simple thing
Reply With Quote
  #2  
Old 08-02-2018, 03:47 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 2,561
gmayor is a jewel in the roughgmayor is a jewel in the roughgmayor is a jewel in the roughgmayor is a jewel in the rough
Default

Sorting paragraphs can be rather hit and miss, but a macro will do it e.g.


Code:
Sub Macro1()
Dim oSource As Document
Dim oDoc As Document
Dim lngPara As Long
Dim oRng As Range
    Set oSource = ActiveDocument
    oSource.Save
    Set oDoc = Documents.Add(oSource.FullName)
    oDoc.Range.Text = ""
    For lngPara = oSource.Paragraphs.Count To 1 Step -1
        Set oRng = oDoc.Range
        oRng.Collapse 0
        oRng.FormattedText = oSource.Paragraphs(lngPara).Range.FormattedText
    Next lngPara
lbl_Exit:
    Set oDoc = Nothing
    Set oSource = Nothing
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Tags
paragraphs, reverse

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
open dialog box in Word has folders in reverse alphabetical order Rewster Word 2 02-20-2017 08:06 AM
Is There an Animation that Will Reverse the Order of a Bulleted List equity PowerPoint 3 04-04-2014 12:33 AM
Reverse Order for Flashcards? bknollman3 PowerPoint 2 03-23-2013 06:34 AM
wildcards in find & replace to reverse word order jeffk Word 3 11-11-2012 01:47 PM
Reverse order of headings throughout Word my_vine_figtree Word VBA 1 08-17-2010 01:46 AM


All times are GMT -7. The time now is 02:16 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft