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!

RTF as email message body with formatting

Status
Not open for further replies.

Strangeway

Programmer
Jul 24, 2008
11
US
Hi guys,

I borrowed the following code from a post by Remou (thanks!) which attaches an RTF document to an email as the message body:

Sub RTFBody()
Const ForReading = 1, ForWriting = 2, ForAppending = 3

Dim fs, f
Dim RTFBody, strTo
Dim MyApp As New Outlook.Application
Dim MyItem As Outlook.MailItem

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.opentextfile("D:\Data\wg400\My Documents\20068B.rtf", ForReading)
RTFBody = f.readall
f.Close

Set MyItem = MyApp.CreateItem(olMailItem)
With MyItem
.To = "blah@blahblah.com"
.Subject = "txtSubjectLine"
.Body = RTFBody
End With
MyItem.Display
End Sub

It works like a charm except that it doesn't display the formatting of the Word document, and instead spits out line after line of the information like this:

"{\rtf1\ansi\ansicpg1252\landscape\paperh12240\paperw15840\margl360\margr360\margt360\margb360\psz1{\colortbl\red0\green0\blue0;\red255\green255\blue255;\red31\green0 etc. etc. etc."

Does anyone know how to resolve this issue?

As usual, all help is greatly appreciated!

Cheers.

"I'm not a programmer... I just say that to meet chicks.
 
Outlook lets you define an email as 'text', RTF or HTML -- the default will probably be text. Is there a property that you can access to tell it to use RTF as the format?
 
It might be connected to the read-only 'EditorType' property which is set for the user in Outlook options.

These are:
olEditorHTML 2
olEditorRTF 3
olEditorText 1
olEditorWord 4

If you create an item, it may respect the user's default editor type and interpret the RTF correctly. I seem to recall you can set Options programatically, but don't remember the calls.

Tools | Options | Mail format (MS Rich Text)

Another option is to use the 'DoCmd.SendObject' action, but I think that writes text from a report or table etc as an RTF attachment to an email, rather than placing it in the body.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top