Home |
Search |
Today's Posts |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
how do i remove the Hard return from a document | Microsoft Word Help | |||
Hard Return in IF field | Microsoft Word Help |