Reading OLE Objects
Attachment objects with a Type
property of CdoOle
are embedded OLE objects. The
Attachment object’s Position property identifies where in the
message to render the OLE object. The Name and Source properties are
not used.
To handle an embedded OLE object, first extract the object from the
message store into a docfile
using the
Attachment object’s WriteToFile method. The next step depends
on the effect desired. One likely possibility is to display the
object in a RichTextBox control. The RichTextBox control makes this
easy with its OLEObjects collection. Merely calling this
collection’s Add method, passing it the name of the
docfile
, inserts the OLE object at the current
insertion point. Here’s the actual
code:
' CdoAttachment and strFilePath already Dim'ed and assigned. ' rtxtBody is a RichTextBox control on the form. CdoAttachment.WriteToFile strFilePath rtxtBody.SelStart = CdoAttachment.Position - 1 rtxtBody.OLEObjects.Add Source:=strFilePath
Three lines to extract an embedded document (of any kind) from an email, and display it to the user. Three lines.
Get CDO & MAPI Programming with Visual Basic: now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.