Thanks Thanks:  0
Likes Likes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Embed several picture in email

  1. #1
    New Member
    Join Date
    Feb 2017
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Embed several picture in email

    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 by L0ndonbound; Oct 10th, 2018 at 09:18 AM.

  2. #2
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,227
    Post Thanks / Like
    Mentioned
    9 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Embed several picture in email

    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

  3. #3
    New Member
    Join Date
    Feb 2017
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Re: Embed several picture in email

    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?

  4. #4
    New Member
    Join Date
    Feb 2017
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Embed several picture in email

    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>"

  5. #5
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,227
    Post Thanks / Like
    Mentioned
    9 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Embed several picture in email

    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

  6. #6
    New Member
    Join Date
    Feb 2017
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Embed several picture in email

    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?

  7. #7
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,227
    Post Thanks / Like
    Mentioned
    9 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Embed several picture in email

    Does the X appear for all three images?

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

  8. #8
    New Member
    Join Date
    Feb 2017
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Embed several picture in email

    Quote Originally Posted by Domenic View Post
    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?

  9. #9
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,227
    Post Thanks / Like
    Mentioned
    9 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Embed several picture in email

    Yeah, the path and filename need to be exact. So is everything working okay?

  10. #10
    New Member
    Join Date
    Feb 2017
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Embed several picture in email

    Quote Originally Posted by Domenic View Post
    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

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •