Embed several picture in email

L0ndonbound

New Member
Joined
Feb 16, 2017
Messages
15
Hi,

I am trying to embed several pictures (they need to be pictures - not based upon the links to the pictures as they are to be emailed to external parties that do not have access to my hard drive) and the following code is displaying the first chart correctly but subsequent ones 2,3,4 etc are showing as the little square with an x in it. What change to my code below do I need to make?

Thanks for advice.


Code:
Sub macro1


Dim olMail As Outlook.MailItem
Dim olapp As Outlook.Application
Dim wEditor As Word.Document

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

Set olapp = CreateObject("Outlook.Application")
Set olMail = olapp.CreateItem(0)
    
    olMail.Display
Set wEditor = olapp.ActiveInspector.WordEditor

With olMail
    .To = "abs@xyz.com"

    olMail.Subject = "xyz"
   

    .HTMLBody = .HTMLBody & "\\local\chart1.png"_
    "\\local\chart2.png" _
    "\\local\chart3.png"
     

    
    
    .Display
End sub
 
Last edited:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
First, attach your .png files to your email, and then embed them within your email using HTML code. Maybe something like this...

Code:
    With olMail
        .Display 'needed to work properly
        .To = "abs@xyz.com"
        .Subject = "xyz"
        .Attachments.Add "\\local\chart1.png"
        .Attachments.Add "\\local\chart2.png"
        .Attachments.Add "\\local\chart3.png"
        .HTMLBody = .HTMLBody & _
            "<p><img src=""cid:chart1.png""></p>" & _
            "<p><img src=""cid:chart2.png""></p>" & _
            "<p><img src=""cid:chart3.png""></p>"
        '.Send
    End With
 
Upvote 0
Thanks Domenic, turns out the other charts I had neglected to add .png to!

However I have a further issue in that some of the charts have parenthouses "[]" and commas ' in the name. ie;

Code:
.HTMLBody = .HTMLBody & "<img src='\\local\chart1.png'>" _
    & "<img src='\\local\chart2.png'>" _
    & "<img src='\\local\chart['456'].png'>"

Chart 1 & chart 2 are added consecutively however chart 456 is not added. Is there a way to add 456 to this email?
 
Upvote 0
Thanks Domenic - please ignore earlier post - I wanted to selete this but couldn't find that option.

That attaches the charts to the email - however theres a couple of issues
1. How can i suppress the display of the attachment - I only want to see the charts in the body of the email
2. The images do not seem to have been loaded to the email - so when sent to someone else it is a link to files on my computer?
3. Some of the charts have parenthouses within the name in addition to commas - eg in the example below chart 1 and chart3 will appear in the body of the email however chart ['2'] will not

.HTMLBody = .HTMLBody & _
"<p><img src=""cid:chart1.png""></p>" & _
"<p><img src=""cid:chart['2'].png""></p>" & _
"<p><img src=""cid:chart3.png""></p>"
 
Upvote 0
Try the following instead...

Code:
    Const olByValue As Integer = 1    
    With olMail
        .Display
        .To = "abs@xyz.com"
        .Subject = "xyz"
        .Attachments.Add "\\local\chart1.png", olByValue, 0
        .Attachments.Add "\\local\chart['2'].png", olByValue, 0
        .Attachments.Add "\\local\chart3.png", olByValue, 0
        .HTMLBody = .HTMLBody & _
            "<p><img src=""cid:chart1.png""></p>" & _
            "<p><img src=""cid:chart['2'].png""></p>" & _
            "<p><img src=""cid:chart3.png""></p>"
        '.Send
    End With
 
Upvote 0
thanks for the revised code but still not working.

It is attaching something but the image is showing an x in the place of the picture, in addition the attachments are suppressed on my side but are still there for the recipient?
 
Upvote 0
Does the X appear for all three images?

Did you check to make sure that the path is correct?
 
Upvote 0
Does the X appear for all three images?

Did you check to make sure that the path is correct?

Yes thanks Domenic.

It wasn't the path - it is because some of the filenames contain spaces i.e. "chart 1" - not "chart1" - the "cid" function seems to not be able to recognice this?
 
Upvote 0
Yeah, the path and filename need to be exact. So is everything working okay?
 
Upvote 0
Yeah, the path and filename need to be exact. So is everything working okay?

No - it isn't working.

Some of the charts have spaces in their names - so while they attach to the email - when the html calls them to add to the body the name is not recognised?

How would I add "chart 1.png" to the body of the email?

Thanks for your help
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top