CDO 1.21 for Outlook 2007 is a separate download from MS. If you have
downloaded that and set a VBA project reference to Microsoft CDO 1.21
Library then you should have no trouble at all with the code at that link.
I'd never bothered translating that CDO code into Outlook 2007 code using
Attachment.PropertyAccessor, but on the fly it would look something like
this for Outlook VBA:
Sub EmbeddedHTMLGraphicDemo()
' Outlook objects
Dim oApp as Outlook.Application
Dim oMsg As Outlook.MailItem
Dim colAttach As Outlook.Attachments
Dim oAttach As Outlook.Attachment
Dim oPA As Outlook.PropertyAccessor
' not an URL, a DASL property tag string
Const PR_ATTACH_MIME_TAG =
"
http://schemas.microsoft.com/mapi/proptag/0x370E001E"
Const PR_ATTACH_CONTENT_ID = "urn:schemas:mailheader:content-id"
' not an URL, a DASL property tag string
Const PR_HIDE_ATTACH = _
"
http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8514000B"
On Error Resume Next
' create new Outlook MailItem
' Use CreateObject for Outlook.Application if not in OL VBA
Set oApp = Application
Set oMsg = oApp.CreateItem(olMailItem)
' add graphic as attachment to Outlook message
' change path to graphic as needed
Set colAttach = oMsg.Attachments
Set oAttach = colAttach.Add("c:\test\graphic.jpg")
oMsg.Save
' *** POSITION CRITICAL *** you must dereference the
' attachment objects before changing their properties
Set colAttach = Nothing
Set oAttach = Nothing
' set properties of the attached graphic that make
' it embedded and give it an ID for use in an <IMG> tag
Set colAttach = oMsg.Attachments
Set oAttach = colAttach.Item(1)
Set oPA = oAttach.PropertyAccessor
oPA.SetProperty PR_ATTACH_MIME_TAG, "image/jpeg"
oPA.SetProperty PR_ATTACH_CONTENT_ID, "myident"
Set oPA = Nothing
Set oPA = oMsg.PropertyAccessor
oPA.SetProperty PR_HIDE_ATTACH, True
oMsg.Save
oMsg.HTMLBody = "<IMG align=baseline border=0 hspace=0 src=cid:myident>"
oMsg.Close olSave
oMsg.Display
' clean up objects
Set colAttach = Nothing
Set oAttach = Nothing
Set oPA = Nothing
Set oMsg = Nothing
Set oApp = Nothing
End Sub