Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VBA - Embed multiple files in Outlook body

Hi.
I am using the following code in Access VBA to send messages. I already have code to
attach multiple files to the message according to the paths held in a ListBox.
What if I want to rather embed multiple images into the body of the messages?
What code would I use? Thanks
Sub SendEmail_Contacts()
 
    Dim olApp As Object, olMsg As Object
    Dim rs As DAO.Recordset
    
    Set olApp = CreateObject("Outlook.Application")
    Set rs = CurrentDb.OpenRecordset("NameOfTable")
    
 
    Do While Not rs.EOF
        If Nz(rs!EmailAddr, "") <> "" Then
            Set olMsg = olApp.CreateItem(0)
            With olMsg
                .To = rs!EmailAddr
                .Subject = rs!Subject
                .Body = rs!Body
                '-------------Embed multiple images (eg HTML) in body -----------
                
                
                
                '-------------add multiple attachments --------------------------
                        Dim j As Integer
                        For j = 0 To FileList.ListCount - 1
                            oMsg.Attachments.Add FileList.Column(0, j)
                        Next j
                '----------------------------------------------------------------
                
                .Send
            End With
        End If
        rs.MoveNext
    Loop
 
    Set olMsg = Nothing
    Set olApp = Nothing
    rs.Close
    Set rs = Nothing
 
    MsgBox "Done"
 
End Sub

Open in new window

Avatar of tabish
tabish

You'll have to attach the messages as usual and then manipulate the HTMLBody of the message.

http://www.outlookcode.com/d/code/htmlimg.htm
Avatar of Murray Brown

ASKER

Hi. Thank you for that code but I still need to embed multiple images. How would one update the code you gave to embed three images
Hi. Thank you for that code but I still need to embed multiple images. How would one update the code you gave to embed three images
I found this article that seems to hint that CDO is not supported for my Outlook 2010
http://blogs.msdn.com/b/deva/archive/2010/01/19/outlook-2010-why-cdo-1-2-1-not-supported-with-outlook-2010.aspx
Avatar of Dale Fye
Have you tried expanding this to include the Outlook and Automation zones.  You might be surprised to know that there are a number of experts in those zones that know their way around VBA but are not Access experts, and some who are Access Experts as well.
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi mwvisa1, thank you, but I am still not clear on this. What code would I use email several html images in the body of an Outlook message for Outlook 2010, where CDO referencing doesn't work.
Thanks very much for the redirection. Great help.
Sorry I missed your earlier message ... was actually sleeping for a change.
However, I see that you have figured out what I was saying.

Glad it helped.

Best regards and happy coding,

Kevin

P.S. If you meant to assign some points to tabish also, please feel free to contact a Moderator as you will have no objections from me as I was trying to help drive home or clarify the point by assisting.