Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add paragraph mark to wrapped lines

Status
Not open for further replies.

jackha18

Technical User
Sep 28, 2002
39
IL
i'm trying to find a proper way to add a paragraph mark to the end of lines that was wrapped by setting right margin.
i tried to save the file in text format but it looses formatting and inappropiate for text with several languages in it.
is there a built-in option in Word to add paragraph (or line break) mark at the end of wrapped line?
 
Could you rephrase that?

Every line is just a line. A paragraph mark is the end of a paragraph, not a line.

If the text is wrapped because it reaches a right margin, then...well it reached the right margin - it is going to wrap.

What exactly are you asking? Do you want to look for where the line breaks (because it reached the right margin) and force that to be a paragraph? Why? What is the purpose of doing that. What is the reason?

If can be done, using the Range of the line, but it does not particularly seem a good idea. However, you may have a reason. Could you clarify what you are trying to do?

Gerry
 
I need to create a document with text of certain width. I use Word to wrap the lines. Then the text will be exported to another program (which doesn't recognize Word's wrapping, only CR or LF).
You're saying one can refer to Range of line - how it can be done - there is no Line object in Word (actually, there is, but it referes to a graphical line, not a line of text).
I must say I have a working solution, but it kind of "emulates" manual line-by-line insertion of CR character by moving cursor through all document's lines. Just like human would do that.
[tt]
While Selection.End <> ActiveDocument.Range.End - 1
'move to end of line
Selection.EndKey Unit:=wdLine, Extend:=wdMove

'insert CR where line wrappes if needed
If Selection.Text <> vbCr Then Selection.Text = vbCr

'jump to next line by moving one char forward
Selection.MoveRight Unit:=wdCharacter, Count:=1
Wend
[/tt]
This is quite slow and I'd be happy to know how can I refer to a line of text, whether it ends with a line break, a paragraph break or just wraped by right margin.
Look at the Word's status bar - there are Ln and Col counter. The Ln counter counts lines no matter if it is a wrapped line or broken line. I also coudn't find what object this counter referes to.
 
OK. I understand. If you are just saving as a text file, this is easy. Look up TextLineEnding in Help for other constants that can be used. However, this only works on txt files.

ActiveDocument.TextLineEnding = wdLFOnly

The line counter refers to the predefined Word bookmark "line", which is essentially (as all bookmarks are) a Range object. The problem is, you still have to use the Selection object to move to the next line. See if the following code works any faster for you. Note, the selection point is moved up one paragraph. This is to cover the Selection point being anywhere OTHER THAN the start of the paragraph. So as long as the selection point is anywhere inside the paragraph, it will change every line end to a paragraph mark.

Code:
Sub AddMarks()
Dim r As Range
Dim var
    Selection.MoveUp Unit:=wdParagraph, Count:=1
With ActiveDocument.Bookmarks("\para").Range
    For var = 1 To ActiveDocument.Bookmarks("\para").Range.ComputeStatistics(wdStatisticLines)
   Set r = ActiveDocument.Bookmarks("\line").Range
      r.Text = r.Text & vbCrLf
   Set r = Nothing
      Selection.GoTo What:=wdGoToLine, Which:=wdGoToNext, Count:=1, Name:=""
    Next
End With
End Sub

Gerry
 
Cool! I've never used bookmars before - I need to learn this feature. Thanks for the help, Gerry.
 
Learn to use bookmarks. Not just the predefined ones, but the ones you create. They are a very powerful feature in Word.

And you are welcome.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top