Solved

VBA - Embed multiple files in Outlook body

Posted on 2010-09-08
11
1,037 Views
Last Modified: 2012-06-21
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

0
Comment
Question by:murbro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 4

Expert Comment

by:tabish
ID: 33626238
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
0
 

Author Comment

by:murbro
ID: 33654166
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
0
 

Author Comment

by:murbro
ID: 33654167
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
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:murbro
ID: 33654724
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
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 33655139
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.
0
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 33655213
It doesn't appear to me that the article you are referencing regarding CDO is relevant here.  In your question you indicated that the code above is working as it stands and all you want to do is add HTML code to the body (i.e.,  tags).  Please try the code given -- see if this reference helps to clarify:

http://msdn.microsoft.com/en-us/library/aa220082(v=office.11).aspx

It is for Office 2003, though, but the HTMLBody should still be correct property of Outlook.MailItem.  To add multiple images, you would do the same you would do on any web page: have multiple img tags.

""

Hopefully you have already accounted for where the images fit within the body HTML coming from database, but other than that think you should be set.
0
 

Author Comment

by:murbro
ID: 33655878
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.
0
 

Author Closing Comment

by:murbro
ID: 33656611
Thanks very much for the redirection. Great help.
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 33656663
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.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question