Removing Line Breaks in Selected Text

K

kansaskannan

I want to be able to select a few lines of text, and then remove all
the line breaks (only) in that selection and replace the linebreak
with a space.

How do I do that? The following code does not work properly. I am
using Word 2003.

Thank you.
---------------------------------------------------------------
Sub SelectionRemoveHardLineBreaks()
Dim oRng As Word.Range
Set oRng = Selection.Range
With oRng.Find
.Text = "^p"
.Replacement.Text = " "
End With

Do While oRng.Find.Execute
With oRng
.Find.Execute Replace:=wdReplaceOne
End With
Loop

End Sub
---------------------------------------------------------------
 
H

Helmut Weber

Hi,

Sub Macro6()
Dim rTmp As Range
Set rTmp = Selection.Range
With rTmp.Find
.Text = Chr(13)
.Replacement.Text = " "
.Wrap = wdFindStop
.Execute Replace:=wdReplaceAll
End With
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
K

kansaskannan

Helmut:

Vielen dank fur die hilfe. Sehr nett von ihnen antwortet zu haben.

kannan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top