Reply
 
Thread Tools Display Modes
  #1   Report Post  
Dennis
 
Posts: n/a
Default VBA to apply a Soft Return (or Hard Return) at end of wrapped line

Office 2003
Word is a wonderful word processer. Visio, expecially, text-box
editing is cryptic at best.

Goal - 1) Type information (For the Visio text Box) in Word
2) Manually ascertain the approx line length that Visio
will handle in that particular text box.
3) Set margins manually in Word to wrap at #2's width
4) VBA-process the word document to place a soft return at
end of the wrapped line (should this be a hard return?)
Visio seems to handle a soft Return while text editing.
(Should I process to file as a word or as a text file?
5) Copy/Paste the processed file into Visio.

Would someone please supply the VBA code for #4 or other advice to help
solve my challenge?

Dennis

  #2   Report Post  
Klaus Linke
 
Posts: n/a
Default

Hi Dennis,

You can try the code below. Not very sophisticated, but it should =
hopefully insert manual line breaks at the end of all wrapped lines in =
the selected text.

If it turns out that Visio can't deal with the manual line breaks, try =
Chr(10) or Chr(13) instead of Chr(11).

Dim myRange As Range
Set myRange =3D Selection.Range.Duplicate
Selection.Collapse (wdCollapseStart)
While Selection.End myRange.End
Selection.EndKey Unit:=3DwdLine
If Selection.Text vbCr Then
Selection.InsertAfter Chr(11)
End If
Selection.Collapse (wdCollapseEnd)
Selection.Move Unit:=3DwdCharacter, Count:=3D1
Wend

Abother option would be to save as "Text with layout", and re-open that =
text file. But that export filter has been removed in Word2003... you'll =
only have it if you have upgraded from an older version.

Regards,
Klaus


"Dennis" schrieb:
Office 2003
Word is a wonderful word processer. Visio, expecially,=20
text-box editing is cryptic at best.
=20
Goal - 1) Type information (For the Visio text Box) in Word
2) Manually ascertain the approx line length that Visio
will handle in that particular text box.
3) Set margins manually in Word to wrap at #2's width
4) VBA-process the word document to place a soft return at
end of the wrapped line (should this be a hard return?)
Visio seems to handle a soft Return while text editing.
(Should I process to file as a word or as a text file?
5) Copy/Paste the processed file into Visio.
=20
Would someone please supply the VBA code for #4 or other advice=20
to help solve my challenge?
=20
Dennis

  #3   Report Post  
Dennis
 
Posts: n/a
Default

Thanks Klaus,

I will try it very soon.

Please check back if there any questions?

Dennis


Klaus Linke wrote:
Hi Dennis,

You can try the code below. Not very sophisticated, but it should

hopefully insert manual line breaks at the end of all wrapped lines in
the selected text.

If it turns out that Visio can't deal with the manual line breaks,

try Chr(10) or Chr(13) instead of Chr(11).

Dim myRange As Range
Set myRange = Selection.Range.Duplicate
Selection.Collapse (wdCollapseStart)
While Selection.End myRange.End
Selection.EndKey Unit:=wdLine
If Selection.Text vbCr Then
Selection.InsertAfter Chr(11)
End If
Selection.Collapse (wdCollapseEnd)
Selection.Move Unit:=wdCharacter, Count:=1
Wend

Abother option would be to save as "Text with layout", and re-open

that text file. But that export filter has been removed in Word2003...
you'll only have it if you have upgraded from an older version.

Regards,
Klaus


"Dennis" schrieb:
Office 2003
Word is a wonderful word processer. Visio, expecially,
text-box editing is cryptic at best.

Goal - 1) Type information (For the Visio text Box) in Word
2) Manually ascertain the approx line length that Visio
will handle in that particular text box.
3) Set margins manually in Word to wrap at #2's width
4) VBA-process the word document to place a soft return at
end of the wrapped line (should this be a hard return?)
Visio seems to handle a soft Return while text editing.
(Should I process to file as a word or as a text file?
5) Copy/Paste the processed file into Visio.

Would someone please supply the VBA code for #4 or other advice
to help solve my challenge?

Dennis


  #4   Report Post  
Greg
 
Posts: n/a
Default

Klaus,

If I can make a suggestions to dress the code up a bit. As is, if the
user selects the final paragraph mark a continous loop occurs. I added
the following lines to prevent this:

Dim i As Integer
i = Selection.StoryType
Set myRange = Selection.Range.Duplicate
If myRange.End = ActiveDocument.StoryRanges(i).End Then
myRange.MoveEnd wdCharacter, -1
End If

  #5   Report Post  
Klaus Linke
 
Posts: n/a
Default

I will :-) ... You can drop me a mail if I don't reply after a few =
days.

Klaus



"Dennis" wrote:
Thanks Klaus,
=20
I will try it very soon.
=20
Please check back if there any questions?
=20
Dennis
=20
=20
Klaus Linke wrote:
Hi Dennis,

You can try the code below. Not very sophisticated, but it should

hopefully insert manual line breaks at the end of all wrapped lines in
the selected text.

If it turns out that Visio can't deal with the manual line breaks,

try Chr(10) or Chr(13) instead of Chr(11).

Dim myRange As Range
Set myRange =3D Selection.Range.Duplicate
Selection.Collapse (wdCollapseStart)
While Selection.End myRange.End
Selection.EndKey Unit:=3DwdLine
If Selection.Text vbCr Then
Selection.InsertAfter Chr(11)
End If
Selection.Collapse (wdCollapseEnd)
Selection.Move Unit:=3DwdCharacter, Count:=3D1
Wend

Abother option would be to save as "Text with layout", and re-open

that text file. But that export filter has been removed in Word2003...
you'll only have it if you have upgraded from an older version.

Regards,
Klaus


"Dennis" schrieb:
Office 2003
Word is a wonderful word processer. Visio, expecially,
text-box editing is cryptic at best.

Goal - 1) Type information (For the Visio text Box) in Word
2) Manually ascertain the approx line length that Visio
will handle in that particular text box.
3) Set margins manually in Word to wrap at #2's width
4) VBA-process the word document to place a soft return at
end of the wrapped line (should this be a hard return?)
Visio seems to handle a soft Return while text editing.
(Should I process to file as a word or as a text file?
5) Copy/Paste the processed file into Visio.

Would someone please supply the VBA code for #4 or other advice
to help solve my challenge?
=20
Dennis




  #6   Report Post  
Dennis
 
Posts: n/a
Default

Thanks Greg!

I was just going to ask about that issue.

Being a Word VBA novice, I will place the first three lines above the
loop and the remainder right before the Wend?

Dennis


Greg wrote:
Klaus,

If I can make a suggestions to dress the code up a bit. As is, if

the
user selects the final paragraph mark a continous loop occurs. I

added
the following lines to prevent this:

Dim i As Integer
i = Selection.StoryType
Set myRange = Selection.Range.Duplicate
If myRange.End = ActiveDocument.StoryRanges(i).End Then
myRange.MoveEnd wdCharacter, -1
End If


  #7   Report Post  
Dennis
 
Posts: n/a
Default

Klaus,

Excellent !! especially with Greg's help.

How could I modify the code to REMOVE any or all (in selected text):
Chr(10) and/or
Chr(11) and/or
Chr(13)

Of course I would use the revised code in a separate macro.

Dennis

  #8   Report Post  
Klaus Linke
 
Posts: n/a
Default

You can use the macro recorder, and record a replacement
Find what: ^10
Replace with:
("Search: Down", leave "Replace with" empty to just remove the Chr(10), =
or type a space if you want/need to insert a space)
Then click on "Replace all" and stop the macro recorder.

Regards,
Klaus

"Dennis" wrote:
Klaus,
=20
Excellent !! especially with Greg's help.
=20
How could I modify the code to REMOVE any or all (in selected text):
Chr(10) and/or
Chr(11) and/or
Chr(13)
=20
Of course I would use the revised code in a separate macro.
=20
Dennis

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i remove the Hard return from a document Hissing Sid Microsoft Word Help 2 February 21st 05 03:42 PM
Hard Return in IF field Ray_Johnson Microsoft Word Help 3 January 4th 05 01:09 AM


All times are GMT +1. The time now is 08:50 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"