none
how to programmatically force carriage return in outlook

    Question

  • I am developing a macro to insert a signature at the end of plain text emails triggered by a shortcut key.  I am using code of the following form:

    With objMail 'objMail is an object of type olMailItem
        .Body = .Body & Chr(13) & Chr(10) & "Department of Microeconomics and Macroeconomics" & Chr(13) & Chr(10) & "University of Springfield"
        .Body = .Body & Chr(13) & Chr(10) & "+1 (800) 555-0606"
     End With

    The trouble is that the carriage returns are not being respected, and the message text renders as follows:

    Department of Microeconomics and Macroeconomics University of Springfield
    +1 (800) 555-0606

     

    Somehow Outlook decides a line is not actually part of a multi-line list but rather a single long sentence.

    I am not interested in switching to HTML mail.  So the question is, is there any way to force outlook to display carriage returns?  I am interested in this question in the more general sense as well.  Outlook often garbles incoming plain text email by removing what it erroneously believes are extraneous carriage returns.  I am assuming this is a special Microsoft "feature," as it does not seem to occur in other mail clients.  Is there any way to override it?  I would prefer a solution that does NOT depend on turning of this "feature" using registry keys or application settings because mail that looks right on my screen will be garbled on the screen of others that use Outlook.

    Friday, September 18, 2009 4:07 PM

Answers

  • Thanks all.  

    The best 'solution' I found is to separate text that needs to be on separate lines by adding 3 spaces at the end of the line, as in:
        .Body = .Body & Chr(13) & "Department of Microeconomics and Macroeconomics   " & Chr(13) & "University of Springfield   "
        .Body = .Body & Chr(13) & "+1 (800) 555-0606"

    What seems to be going on is that Outlook is reflowing the text.  If there are only one or two spaces at the end of the line, Outlook infers that the before text and the after text might all be part of one sentence, and so decides to treat it as one (I suspect this is to eliminate "phony" carriage returns automatically inserted by old-fashioned text editors (e.g., Pine) with fixed line widths when you run onto the next line).  But if you have THREE spaces, Outlook acts as if to say "oh, okay, this really SHOULD be kept separate no matter what."

    Note that this happens even when opening OTHER people's plain text emails!  Hence my concern about how it would show up on other monitors/computers.  The "three space" solution is not a 100% perfect solution because it looks kind of funny when the text is highlighted, but it seems to solve my problem.  And the text will appear properly on other screens, too.
    • Marked as answer by zipblack Monday, September 28, 2009 2:46 AM
    Monday, September 28, 2009 2:46 AM
  • Hi, I have experiemented with your problem and I get the same issues regardless of what tricks I try to play on Outlook. The nearest I got to solving this is to toggle the body type just before adding the signature text, then toggling it back as below:

         .BodyFormat = olFormatHTML
           .Body = .Body & Chr(13) & Chr(10) & "Department of Microeconomics and Macroeconomics" & Chr(13) & Chr(10) & "University of Springfield"
            .Body = .Body & Chr(13) & Chr(10) & "+1 (800) 555-0606"
            .BodyFormat = olFormatPlain

    If Outlook let you programatically add a stored signature this would be much better, but up to Office 2003 I dont think this is possible.

    Regards

    ADG
    • Marked as answer by Tim Li Monday, September 28, 2009 2:21 AM
    Wednesday, September 23, 2009 7:30 AM

All replies

  • Hi Zipblack,

    Try "vbLf" or "vbCr" instead of "Chr(13)"

    Regards,
    Manoj Mishra
    • Marked as answer by Tim Li Monday, September 28, 2009 2:21 AM
    • Unmarked as answer by zipblack Monday, September 28, 2009 2:35 AM
    Tuesday, September 22, 2009 10:48 PM
  • Hi, I have experiemented with your problem and I get the same issues regardless of what tricks I try to play on Outlook. The nearest I got to solving this is to toggle the body type just before adding the signature text, then toggling it back as below:

         .BodyFormat = olFormatHTML
           .Body = .Body & Chr(13) & Chr(10) & "Department of Microeconomics and Macroeconomics" & Chr(13) & Chr(10) & "University of Springfield"
            .Body = .Body & Chr(13) & Chr(10) & "+1 (800) 555-0606"
            .BodyFormat = olFormatPlain

    If Outlook let you programatically add a stored signature this would be much better, but up to Office 2003 I dont think this is possible.

    Regards

    ADG
    • Marked as answer by Tim Li Monday, September 28, 2009 2:21 AM
    Wednesday, September 23, 2009 7:30 AM
  • Thanks all.  

    The best 'solution' I found is to separate text that needs to be on separate lines by adding 3 spaces at the end of the line, as in:
        .Body = .Body & Chr(13) & "Department of Microeconomics and Macroeconomics   " & Chr(13) & "University of Springfield   "
        .Body = .Body & Chr(13) & "+1 (800) 555-0606"

    What seems to be going on is that Outlook is reflowing the text.  If there are only one or two spaces at the end of the line, Outlook infers that the before text and the after text might all be part of one sentence, and so decides to treat it as one (I suspect this is to eliminate "phony" carriage returns automatically inserted by old-fashioned text editors (e.g., Pine) with fixed line widths when you run onto the next line).  But if you have THREE spaces, Outlook acts as if to say "oh, okay, this really SHOULD be kept separate no matter what."

    Note that this happens even when opening OTHER people's plain text emails!  Hence my concern about how it would show up on other monitors/computers.  The "three space" solution is not a 100% perfect solution because it looks kind of funny when the text is highlighted, but it seems to solve my problem.  And the text will appear properly on other screens, too.
    • Marked as answer by zipblack Monday, September 28, 2009 2:46 AM
    Monday, September 28, 2009 2:46 AM