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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook 2007 Save as text file breaks long text lines 1

Status
Not open for further replies.

traceyr

Technical User
Aug 16, 2002
41
DE
I regularly receive emails in Outlook 2007 with text in the mail body. If I copy/paste the body into a text editor, the text file retains the original line lengths (in this case up to 131 characters). However if I use File/"Save as" to a text file, Outlook inserts line breaks at or near char. 72 (at the nearest breaking character or space?); the same happens in a VBA macro, which is what I want to use to automate the process for the users. I have tried "Array() = Split(<emailbody> vbCRLF)" to create an array of text lines, but that creates an empty array (no vbCRLF it seems).

Any ideas and/or suggestions would be most welcome.
 

hi,

Your code???

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Sorry, here it is (cobbled together from stuff found on the web, of course!). I was wondering whether the body's lines are terminated by something other than CRLF, whether the body object already has the line breaks in it before the saveas takes place (in which case I'm scuppered!). Also I'm new to VBA, so don't assume anything about things that I have possibly tried already!!

Sub TempReport1()
On Error Resume Next
Dim objNS As Outlook.NameSpace
Dim objItem As Outlook.MailItem
Dim arrLines() As String
Dim strBody As String
Dim iCount As Integer
Dim fso As New FileSystemObject
Dim ts As TextStream
Dim elements As Long

Set objNS = Application.GetNamespace("MAPI")
Set ts = fso.CreateTextFile("C:\Reports\TempReport.txt", True)

' nothing selected
If Application.ActiveExplorer.Selection.Count <> 1 Then
MsgBox "Select one email please"
Exit Sub
End If

For Each objItem In Application.ActiveExplorer.Selection
If objItem.Class = olMail Then
objItem.BodyFormat = olFormatPlain 'Converts body to Plain text format
ts.Write objItem.Body
End If
Next
ts.Close

Set objItem = Nothing
Set objNS = Nothing
End Sub
 



hi,

Changed your code as it would not run in my Outlook 2007 with Option Explicit.

1690 bytes, 387 words - NO added CR or LF
Code:
    Dim fso As Object
    Dim ts As Object
    Set fso = CreateObject("Scripting.FileSystemObject")


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks. I tried the changed but it hasn't changed the result for me! That suggests to me that the error is in my Outlook setup (Outlook 2007, Win7).
 
I have come across this information from May 2011 on an official Microsoft technet forum (social.technet.microsoft.com/Forums/en-US/outlook/thread/77bfc9b0-adcc-4a89-9512-45ce7235cd6f/?prof=required):

"Save As Text" feature adds unwanted linebreaks to the body of the message because the text is being hard-wrapped to a length between 30 and 132 characters. This is by design and the reason why this is happening is because of the text converter that outlook and word use to convert the body to plain text.

This has been highlighted to the Product team so a possible design change can be incorporated in Outlook. But unfortunately I cannot assure you that this change would be incorporated in Outlook".

So there's a solid problem here. Skip: Did you have lines >72 in your text data?
 


Yes. I entered "Now is the time for all good men to come to the aid of their counrty" into a Word doc, several times, making sure that all the sentences were in ONE paragraph with no line feed or chariage return: 1690 bytes, 387 words. Then pasted that into a new mail item.

Oddly enough, the FIRST time I ran your code, I got CR after each sentence. When I ran again, I got one paragraph. Wierd!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Good news: I tried changing the format to HTML before saving, since there's no markup, just plain text. And it works!

For Each objItem In Application.ActiveExplorer.Selection
If objItem.Class = olMail Then
'Convert body to HTML format, which produces the desired result!
objItem.BodyFormat = olHTML
ts.Write objItem.Body
End If
Next

Maybe Microsoft owes me one!
 


Appreciate your perseverance and then sharing your sucessful conclusion with the Tek-Tip members.

[purple]===> *[/purple]

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Update and request for help:

The technique I use to create text from the email body (changing the body to HTML format) no longer works, since the body now contains some Japanese characters in Unicode! Before I start working out how to sort out this new problem, has anyone a suggestion as to how to approach this? Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top