Merging paragraphs in MS Word 2007

Posted by Rajneesh Jain on Super User See other posts from Super User or by Rajneesh Jain
Published on 2012-06-18T08:39:11Z Indexed on 2012/06/18 9:18 UTC
Read the original article Hit count: 404

Filed under:

My name is Rajneesh Jain from New Delhi, India. I saw your code on merging and re-formatting paragraphs in MS Word 2007. I am facing problem of text overflow.

The code I used is:

Sub FixParagraph() ' ' FixParagraph Macro ' ' Dim selectedText As String Dim textLength As Integer

selectedText = Selection.Text

' If no text is selected, this prevents this subroutine from typing another
' copy of the character following the cursor into the document
If Len(selectedText) <= 1 Then
    Exit Sub
End If

' Replace all carriage returns and line feeds in the selected text with spaces
selectedText = Replace(selectedText, vbCr, " ")
selectedText = Replace(selectedText, vbLf, " ")

' Get rid of repeated spaces
Do
    textLength = Len(selectedText)
    selectedText = Replace(selectedText, "  ", " ")
Loop While textLength <> Len(selectedText)

' Replace the selected text in the document with the modified text
Selection.TypeText (selectedText)

End Sub

© Super User or respective owner

Related posts about windows-xp