#16
|
||||
|
||||
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
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#17
|
|||
|
|||
Quote:
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~ |
#18
|
||||
|
||||
The code I provided assumes your sample separates content by paragraph marks. As you have just discovered, your provided sample does but your REAL document doesn't.
I'm happy to revisit the code only if you provide a realistic sample (in Word format) so that I can see what you are actually dealing with. Although you are under the impression that screen captures gives me an accurate idea on what the underlying content structure is - I can assure you it doesn't. The sample needs to include examples of your bulleted list elements which should be included with the parent paragraph. The spacing issue is easy enough to solve but the 'separation of related things' issue needs to be addressed after looking at structure of your docs.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#19
|
|||
|
|||
Quote:
Also don't worry about it being an example document; if the macro works for this one it'll work for the ones I work with. Please understand those are private :] |
#20
|
||||
|
||||
Based on that sample doc, this code appears to work
Code:
Sub SortParasBySize() Dim aRng As Range, aTable As Table, aRow As Row ActiveWindow.View = wdNormalView With ActiveDocument.Range.Find 'Do Find and Replace for separators .ClearFormatting .Replacement.ClearFormatting .Text = "^p" .Replacement.Text = "zx" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Execute Replace:=wdReplaceAll .Text = "zxzx" .Replacement.Text = "^p" .Execute Replace:=wdReplaceAll ActiveDocument.Range.ConvertToTable Separator:=wdSeparateByParagraphs, NumColumns:=1 .Text = "zx" .Replacement.Text = "^p" .Execute Replace:=wdReplaceAll End With 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.Columns.Add 'insert empty column to reinstate extra paras between sections aTable.Rows(1).Delete aTable.ConvertToText Separator:=wdSeparateByParagraphs End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#21
|
|||
|
|||
Quote:
Wow, you're awesome dude. Thank you so much for taking the time to make such a useful tool. And sorry it took me so long to provide you a document so you could test it properly :] The only unexpected thing it does is it changes the view from the Print Layout View (which I usually use) to the Normal View, seen at the very bottom left of the screen. Which isn't a big deal at all; I can just click Print Layout View again and it's back~ |
#22
|
||||
|
||||
I changed the view in an attempt to speed up the macro because you said the earlier one was very slow. I didn't do any speed tests because I didn't have a big file to test on but in theory, this should help the macro run faster because it reduces the repagination load.
You can disable that line up at the top of the macro. Or add a line to return the view the page view at the end of the macro.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#23
|
|||
|
|||
Quote:
Thanks again and I'll let you guys know if I notice anything else with the two macros made here~ |
Tags |
help me, macros, ms word |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to automatically enable the macros upon opening a file with macros? | laurieli | Office | 7 | 01-17-2016 08:56 AM |
Can you make templates dynamically update macros/etc. from Normal.DOT? | New Daddy | Word | 2 | 11-18-2013 09:07 AM |
VBA macros | tays01s | Word VBA | 6 | 08-03-2011 09:42 PM |
Macros | nore | Outlook | 0 | 06-01-2011 04:39 PM |
Macros | Desertwrangler | Word VBA | 6 | 06-25-2010 07:06 AM |