View Single Post
Old 02-26-2010, 11:02 AM   #2
steven522
binomial: homo legentem
steven522 ought to be getting tired of karma fortunes by now.steven522 ought to be getting tired of karma fortunes by now.steven522 ought to be getting tired of karma fortunes by now.steven522 ought to be getting tired of karma fortunes by now.steven522 ought to be getting tired of karma fortunes by now.steven522 ought to be getting tired of karma fortunes by now.steven522 ought to be getting tired of karma fortunes by now.steven522 ought to be getting tired of karma fortunes by now.steven522 ought to be getting tired of karma fortunes by now.steven522 ought to be getting tired of karma fortunes by now.steven522 ought to be getting tired of karma fortunes by now.
 
steven522's Avatar
 
Posts: 1,061
Karma: 25222222
Join Date: Feb 2010
Location: Alabama, USA
Device: iriver Story HD; Archos 80 G9
Made an improvement to handle some formats that use spaces instead of tabs to indent that was causing issues with some file conversions.


Code:
Option Explicit
Sub ReformatText()
    ' ReformatText Macro
    
    '  Replace all CRLF (paragraph) with "~~" marker
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p"
        .Replacement.Text = "~~"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    
    '  Replace all double "~~" markers with a double
    '  CRLF (paragraph) format code
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "~~~~"
        .Replacement.Text = "^p^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    
    '  Replace all remaining "~~" markers with a space
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "~~"
        .Replacement.Text = " "
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    
End Sub
steven522 is offline   Reply With Quote