#1
|
|||
|
|||
Question about sorting paragraphs in Word 2007
I'm working with an equalizer preset .ini file from AIMP3 media player. When AIMP3 saves a preset, it adds it to the end of the .ini file and the only way to change it's order is manually cut and paste it then save the file. There's no sort option in the interface. After accumulating many, many entries, I thought it would be a good idea to arrange them alphabetically. Rather than doing them all manually, I was hoping I could do them automatically in Word but there's a slight problem. Here's an example of what the entries look like in the .ini file:
[Alan Parsons Project] Band0=-15 Band1=-15 Band2=0 Band3=-3 Band4=-6.59999990463257 Band5=-6.59999990463257 Band6=-6.59999990463257 Band7=-2.40000009536743 Band8=-2.40000009536743 Band9=-2.40000009536743 Band10=-2.40000009536743 Band11=4.5 Band12=9.60000038146973 Band13=9.60000038146973 Band14=13.5 Band15=13.5 Band16=13.5 Band17=-15 Version=2 [Wilco] Band0=-15 Band1=-15 Band2=0 Band3=-3 Band4=-6.59999990463257 Band5=-6.59999990463257 Band6=-6.59999990463257 Band7=-2.40000009536743 Band8=-2.40000009536743 Band9=-2.40000009536743 Band10=-2.40000009536743 Band11=4.5 Band12=9.60000038146973 Band13=9.60000038146973 Band14=13.5 Band15=13.5 Band16=13.5 Band17=-15 Version=2 I'd like to be able to sort each paragraph alphabetically according to the first word and ignore the [ but I'm not sure this is possible. Does anyone know of an easy way to do this, at least easier than doing them manually? Thanks. |
#2
|
||||
|
||||
Hi Walt,
After copying the data to Word, you could use a macro: Code:
Sub Demo() Application.ScreenUpdating = False Dim Tbl As Table With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^13([!\[])" .Replacement.Text = "|\1" .Forward = True .Wrap = wdFindContinue .Format = False .MatchWildcards = True .Execute Replace:=wdReplaceAll End With Set Tbl = .ConvertToTable(Separator:=wdSeparateByParagraphs, NumColumns:=1) With Tbl .Sort ExcludeHeader:=False, FieldNumber:="Column 1", CaseSensitive:=False, _ SortFieldType:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending .Rows.ConvertToText Separator:=wdSeparateByParagraphs End With With .Find .Text = "|" .Replacement.Text = "^p" .Execute Replace:=wdReplaceAll .Text = "([!^13])^13\[" .Replacement.Text = "\1^p^p[" .Execute Replace:=wdReplaceAll End With While .Characters.Last.Previous.Text = vbCr .Characters.Last.Previous.Text = vbNullString Wend End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
macropod, once again you've made some magic for me. Worked like a charm and I can't thank you enough!
|
#4
|
|||
|
|||
This is an excellent macro, but after using it awhile I've found one small problem. Here's an example (I listed them horizontally on purpose because I can't get them to list vertically for some reason): [Rock n Roll Soul] [Rock n Roll] [Rock].
Technically, shouldn't [Rock] be first? This is just one example but it does it a lot. I've tried to figure out how to change it but I'm not having any luck. Anyone see a fix? I'm using the macro exactly as written above. Thank you. EDIT: It gets it basically right, A, B, C, etc., but within each group some entries aren't where I would expect them. Now that I think about it, I'd expect those three entries in the example above to be in the reverse order of which they are. Last edited by WaltR; 02-21-2014 at 01:37 PM. |
#5
|
||||
|
||||
Seems I hadn't made sufficient provision for what follows the titles. Try:
Code:
Sub Demo() Application.ScreenUpdating = False Dim Tbl As Table With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .Format = False .MatchWildcards = True .Text = "^13([!\[])" .Replacement.Text = "|\1" .Execute Replace:=wdReplaceAll .Text = "\]^13" .Replacement.Text = "^t^&" .Execute Replace:=wdReplaceAll End With Set Tbl = .ConvertToTable(Separator:=wdSeparateByTabs, NumColumns:=2) With Tbl .Sort ExcludeHeader:=False, FieldNumber:="Column 1", CaseSensitive:=False, _ SortFieldType:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending .Rows.ConvertToText Separator:=wdSeparateByParagraphs End With With .Find .Text = "|" .Replacement.Text = "^p" .Execute Replace:=wdReplaceAll .Text = "^13(\])" .Replacement.Text = "\1" .Execute Replace:=wdReplaceAll .Text = "([!^13])(^13\[)" .Replacement.Text = "\1^p\2" .Execute Replace:=wdReplaceAll End With While .Characters.Last.Previous.Text = vbCr .Characters.Last.Previous.Text = vbNullString Wend End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
macropod, I've gotta hand it to you, you're a genius. It was great before, now it's perfect. I use this macro all the time, I'd be lost without it.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Outlook 2007 Sorting roblem | tgulez | Outlook | 2 | 08-02-2011 12:04 AM |
Word 2007 - Index question | history | Word | 0 | 09-02-2010 05:01 AM |
Product Key Question - Word 2007 | bob369 | Office | 2 | 08-21-2010 09:50 PM |
Sorting question | markg2 | Excel | 4 | 01-25-2010 03:13 PM |
indenting paragraphs in word 2007 | Brent | Word | 0 | 01-17-2010 10:01 AM |