View Single Post
Old 09-11-2008, 12:18 AM   #6
FizzyWater
You kids get off my lawn!
FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.
 
FizzyWater's Avatar
 
Posts: 4,220
Karma: 73492664
Join Date: Aug 2007
Location: Columbus, Ohio
Device: Oasis 2 and Libra H2O and half a dozen older models I can't let go of
I played a little with Word macros and came up with the following to do what the other poster suggested doing in the "Find" and "Replace" boxes. I only tested this on one document, so you might want to test this on some of the documents you typically convert.

Code:
Sub ParagraphBreaksInMiddleOfSentences()

    Selection.WholeStory
    
    'to delete all section breaks first (replace the ^b if you
    'want to delete all section *and* page breaks or ^m if
    'you want to delete only page breaks)
    With Selection.Find
        .Text = "^b"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    'resets FindAndReplace parameters to defaults before running next one
    Call ClearFindAndReplaceParameters
    
    'to replace any combination of a paragraph return,
    'then a lower case letter, with a space and the
    'same lower case letter
    With Selection.Find
        .Text = "^13([a-z]?)"
        .Replacement.Text = " \1"
        .MatchWildcards = True
        .Forward = True
        .Wrap = wdFindContinue
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Call ClearFindAndReplaceParameters
    
    'to replace any combination of a line feed, then a
    'lower case letter, with a space and the same lower
    'case letter
    With Selection.Find
        .Text = "^l([a-z]?)"  'this is a caret (^) and a lower case L (l)
        .Replacement.Text = " \1"
        .MatchWildcards = True
        .Forward = True
        .Wrap = wdFindContinue
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Call ClearFindAndReplaceParameters

End Sub

Sub ClearFindAndReplaceParameters()
' copied from word.mvps.org

  With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
  End With

End Sub
Quote:
=X= said:
//**Here is the inconsistency. New paragraphs are ^p which is not the same as ^13 which is a new line. When using the "Use Wildcards" option the ^p is not supported, so there will be cases where you will not find text using the expression in line 4.
The Microsoft Office website specifically listed the ^13 as a replacement for the paragraph mark. When I tested created paragraph returns versus line returns, the ^13 replaced all the paragraph returns and the ^l replaced all the line returns.

I use Windows, so it may be that this works different in other operating systems. But as I said above, I really only tested this on one "real" ebook and just one single-sentence test file...so I could be wrong.

Last edited by FizzyWater; 09-11-2008 at 12:29 AM. Reason: to get code to display indents properly
FizzyWater is offline   Reply With Quote