Add a paragraph mark at the end of every line?

O

OKLover

Hi, All

How do I add a paragraph mark at the end of every line with VBA ?


Regards

David
 
F

Fumei2 via OfficeKB.com

What do you mean by "line"? Is each "line" terminated by a manual line break?


You could try doing a Find/Replace.

Use ^l for the Find
Use ^p for the Replace.

Why do you need VBA?
 
O

OKLover

Yes.

Is any suggestion?

Fumei2 via OfficeKB.com said:
What do you mean by "line"? Is each "line" terminated by a manual line break?


You could try doing a Find/Replace.

Use ^l for the Find
Use ^p for the Replace.

Why do you need VBA?


--
Gerry



.
 
O

OKLover

sorry... updated informationas below:

It should be each line as a paragraph. That means each "line" terminated by
a paragraph break {ENTER} not {SHIFT+ENTER}.


Many Thanks

David
 
D

Doug Robbins - Word MVP

Saving the document as a .txt file can be used to do that.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
O

OKLover

Wow ~ Robbins, you are so cool.

Yes! It can do that, but does it possible to loop each line to check via VBA
code?


Many thanks

David
 
D

Doug Robbins - Word MVP

The following code will create a new document containing each line from the
document that was active when it is run as a separate paragraph in that
document

Dim source As Document, target As Document
Dim numlines As Long
Set source = ActiveDocument
Set target = Documents.Add
On Error GoTo LastLine
With source
.Activate
Selection.HomeKey wdStory
Do While .Bookmarks("\line").Range.End <> .Range.End
target.Range.InsertAfter .Bookmarks("\line").Range.Text & vbCr
.Bookmarks("\line").Range.Cut
Loop
End With
LastLine:
target.Range.InsertAfter source.Bookmarks("\line").Range.Text


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
F

Fumei2 via OfficeKB.com

"That means each "line" terminated by
a paragraph break {ENTER} not {SHIFT+ENTER}."

A Shift+Enter is ^l in the Find/replace dialog.
An Enter (paragraph mark) is ^p

What was wrong with my suggestion? Do a find/replace changing Shift+enter to
Enter.

Find: ^l
Replace ^p
Dear Robbins,

Thanks for your kindly answer.

Best Regards

David
The following code will create a new document containing each line from the
document that was active when it is run as a separate paragraph in that
[quoted text clipped - 57 lines]
 
F

Fumei2 via OfficeKB.com

And if you really want to use VBA...


Sub LineBreaksToParaMarks()
Selection.HomeKey Unit:=wdStory
With Selection.Find
.Text = "^l"
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceAll
End With
End Sub

Gerry
"That means each "line" terminated by
a paragraph break {ENTER} not {SHIFT+ENTER}."

A Shift+Enter is ^l in the Find/replace dialog.
An Enter (paragraph mark) is ^p

What was wrong with my suggestion? Do a find/replace changing Shift+enter to
Enter.

Find: ^l
Replace ^p
Dear Robbins,
[quoted text clipped - 9 lines]
 
D

Doug Robbins - Word MVP

That only works if the lines were terminated by the use of Shift+Enter.

If that was not used (the text wrapped automatically), there will be no ^l
to replace.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

Fumei2 via OfficeKB.com said:
And if you really want to use VBA...


Sub LineBreaksToParaMarks()
Selection.HomeKey Unit:=wdStory
With Selection.Find
.Text = "^l"
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceAll
End With
End Sub

Gerry
"That means each "line" terminated by
a paragraph break {ENTER} not {SHIFT+ENTER}."

A Shift+Enter is ^l in the Find/replace dialog.
An Enter (paragraph mark) is ^p

What was wrong with my suggestion? Do a find/replace changing Shift+enter
to
Enter.

Find: ^l
Replace ^p
Dear Robbins,
[quoted text clipped - 9 lines]

--
Gerry

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201006/1
 

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