Merging paragraphs in MS Word 2007
- by Rajneesh Jain
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