View Single Post
 
Old 08-18-2020, 07:43 PM
grumblid grumblid is offline Windows 7 64bit Office 2003
Novice
 
Join Date: Jul 2016
Posts: 25
grumblid is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
If you don't think it is important enough to provide realistic content and show the hidden formatting then I will just give you a macro that works with the content we assume you have provided.

Try this on a copy of your example document. If it works, try it on a copy of your real document.
Code:
Sub SortParasBySize()
  Dim aRng As Range, aTable As Table, aRow As Row

  ActiveDocument.Range.ConvertToTable Separator:=wdSeparateByParagraphs, NumColumns:=1
  Set aTable = ActiveDocument.Tables(1)
  aTable.Columns.Add BeforeColumn:=aTable.Columns(1)
  For Each aRow In aTable.Rows
    aRow.Cells(1).Range.Text = Len(aRow.Cells(2).Range.Text)
  Next aRow
  aTable.Rows.Add BeforeRow:=aTable.Rows(1)
  aTable.SortDescending
  aTable.Columns(1).Delete
  aTable.Rows(1).Delete
  aTable.ConvertToText
End Sub
Thanks~ So this almost works! I tried it with a 400-page document and Charles was right about it taking a long time to load. After around 20 minutes I just closed it because I had a feeling it wasn't going anywhere.

But believe it or not, though it still takes a little while to load (2 or 3 minutes, possibly a little more), it was able to work on a 100 page document.

The only problem is while it does organize everything biggest to smallest, everything is clumped together without the vertical spaces each of the bodies of text previously had.

Also if there was a body of text that had a list of things:
- Like
- This
- Kind
- Of
- List,

those individual words were at the very bottom of the document instead of remaining an intact list (staying with the 6-row entries since that example list has 6 rows). But that's not that big of a deal. I just thought I'd let you know :]

If we could solve the spacing issue, I'd say it would pretty much be the macro I was dreaming of, haha~
Reply With Quote