Word - Add a paragraph mark at the end of every line?
Asked By OKLover on 01-Jun-10 12:20 PM
Hi, All
How do I add a paragraph mark at the end of every line with VBA ?
Regards
David
Fumei2 via OfficeKB.com replied to OKLover on 01-Jun-10 07:16 PM
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
Message posted via http://www.officekb.com
OKLover replied to Fumei2 via OfficeKB.com on 01-Jun-10 05:59 PM
OKLover replied to Fumei2 via OfficeKB.com on 01-Jun-10 06:16 PM
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
Doug Robbins - Word MVP replied to OKLover on 02-Jun-10 05:09 AM
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
OKLover replied to Doug Robbins - Word MVP on 02-Jun-10 05:23 AM
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
Doug Robbins - Word MVP replied to OKLover on 02-Jun-10 06:26 AM
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
OKLover replied to Doug Robbins - Word MVP on 03-Jun-10 07:03 AM
Dear Robbins,
Thanks for your kindly answer.
Best Regards
David
Fumei2 via OfficeKB.com replied to OKLover on 03-Jun-10 07:45 PM
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
--
Gerry
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201006/1
Fumei2 via OfficeKB.com replied to Fumei2 via OfficeKB.com on 03-Jun-10 07:48 PM
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
--
Gerry
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201006/1
Doug Robbins - Word MVP replied to Fumei2 via OfficeKB.com on 03-Jun-10 07:55 PM
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