Microsoft KB Archive/179084

= How To Print Messages in Rich Text Using Outlook Object Model =

Article ID: 179084

Article Last Modified on 3/21/2005

-

APPLIES TO


 * Microsoft Outlook 97 Standard Edition
 * Microsoft Exchange Development Kit 5.5
 * Microsoft Exchange Development Kit 5.5

-



This article was previously published under Q179084



SUMMARY
A fairly common request of a messaging application is to print an e-mail message in Rich Text Format (.rtf). This article describes how to use the Outlook object model to accomplish this task.



MORE INFORMATION
Because Messaging Application Programming Interface (MAPI) stores .rtf files in a compressed format in the PR_RTF_COMPRESSED field in a message, it is not possible to print just the contents of the field and get any meaningful results.

Printing a message in its original Rich Text Format is not possible for Collaboration Data Objects (CDO) without calling custom extensions. Please see the article listed in the REFERENCES section for more information.

The other alternative is to use Extended MAPI, which unfortunately is not available to Visual Basic developers due to language limitations.

The Exchange Appfarm includes a sample called ExPrint in the Misc Tools section. ExPrint automatically prints a new incoming message, but will apply its own formatting to the message content. Build the code sample below into an .exe file and use it in place of the Visual Basic .exe file that ExPrint instructs you to execute. Please refer to the REFERENCES section for the location of the sample.

The following code sample demonstrates a process that you can use to print not only your e-mail messages, but also any attachments (as long as they have a registered OLE Server on the system) in their original rich-text format.

Sample Code
'This code sample assumes a reference to the 'Outlook object model (MSOUTL8.OLB). Dim myOlApp As Object Dim olNameSpace As Object Dim myItem As Object

Sub Main Set myOlApp = CreateObject("Outlook.Application") Set olNameSpace = myOlApp.GetNamespace("MAPI") Set myItem = olNameSpace.GetItemFromID(Command)

myItem.Display myItem.PrintOut myItem.Close 1

End Sub

