Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-19-2013, 01:30 PM
WaltR WaltR is offline Windows Vista Office 2007
Competent Performer
Question about sorting paragraphs in Word 2007
 
Join Date: Dec 2010
Posts: 123
WaltR is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 05-19-2013, 03:07 PM
macropod's Avatar
macropod macropod is offline Question about sorting paragraphs in Word 2007 Windows 7 32bit Question about sorting paragraphs in Word 2007 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
For installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-20-2013, 11:51 AM
WaltR WaltR is offline Windows Vista Office 2007
Competent Performer
Question about sorting paragraphs in Word 2007
 
Join Date: Dec 2010
Posts: 123
WaltR is on a distinguished road
Default

macropod, once again you've made some magic for me. Worked like a charm and I can't thank you enough!
Reply With Quote
  #4  
Old 02-21-2014, 08:46 AM
WaltR WaltR is offline Windows Vista Office 2007
Competent Performer
Question about sorting paragraphs in Word 2007
 
Join Date: Dec 2010
Posts: 123
WaltR is on a distinguished road
Default

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.
Reply With Quote
  #5  
Old 02-21-2014, 08:16 PM
macropod's Avatar
macropod macropod is offline Question about sorting paragraphs in Word 2007 Windows 7 32bit Question about sorting paragraphs in Word 2007 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #6  
Old 02-21-2014, 09:16 PM
WaltR WaltR is offline Windows Vista Office 2007
Competent Performer
Question about sorting paragraphs in Word 2007
 
Join Date: Dec 2010
Posts: 123
WaltR is on a distinguished road
Default

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.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about sorting paragraphs in Word 2007 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
Question about sorting paragraphs in Word 2007 Product Key Question - Word 2007 bob369 Office 2 08-21-2010 09:50 PM
Question about sorting paragraphs in Word 2007 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

Other Forums: Access Forums

All times are GMT -7. The time now is 09:44 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft