line break

R

rani

i want to add the text "line break start" before the beginning of new line
and add "line break ends" after the end of the line for all the lines in MS
word doc using VBA.

can any one help me with the code of it?
 
H

Helmut Weber

Hi Rani,

lines or paragraphs?

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Helmut Weber

Hi Rani,

very likely this isn't possible at all,
if there are automatic linebreaks.

If there are manual linebreaks,
then strictly speaking, it is impossible
even in theory, as the linebreak is a part of the line.
You wold have to insert your text *immediately before*
the line's end.

Which may result in a new different automatic linebreak,
and increase the number of lines of the doc.

You may play a bit with the following,
just to see, why it doesn't work.

Sub Macro3()
Dim lngL As Long
Dim lngC As Long
ActiveDocument.Range(0, 0).Select
selection.ExtendMode = False
lngL = ActiveDocument.BuiltInDocumentProperties("Number of lines")
For lngC = 1 To lngL
selection.GoTo what:=wdGoToLine, _
which:=wdGoToAbsolute, _
Count:=lngC
selection.Bookmarks("\line").Range.InsertBefore "yyyy"
selection.Bookmarks("\line").Range.InsertAfter = "xxxx"
Next
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Doug Robbins - Word MVP

That is going to really screw up the present line breaks. When you add the
"line break start" at the beginning of the line, some of the text that was
towards the end of the line will wordwrap onto the next line.

--
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
 
R

rani

Thanks Doug. that was quite helpful

Doug Robbins - Word MVP said:
That is going to really screw up the present line breaks. When you add the
"line break start" at the beginning of the line, some of the text that was
towards the end of the line will wordwrap onto the next line.

--
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
 

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