1

I'm trying to build an email that has both text and an image (chart from Excel) using HTML code. I merged code I found online.

This is what I have so far for the image:

FirstChartPath = ThisWorkbook.Path & "\Current Credit Usage.png"
ChartName = "Current Credit Usage.png"
'add the image in hidden manner, position at 0 will make it hidden
.Attachments.Add FirstChartPath, olByValue, 0

'Now add it to the Html body using image name

'change the src property to 'cid:your image filename'
'it will be changed to the correct cid when its sent.
.HTMLBody = .HTMLBody & "<br><B>CURRENT CREDIT USAGE:</B><br>" _
  & "<img src='cid:Current Credit Usage.png'" & "width='500' height='200'>"
  '& "<br>Best Regards, <br>Sumit</font></span>"

I get an "X" in the image saying the linked image cannot be displayed.

"The file may have been moved, renamed or deleted. Verify that the link points to the correct file and location"

Community
  • 1
  • 1
Federico Sanchez
  • 145
  • 1
  • 2
  • 12
  • Shouldn't there be a space between the source file and the width. Not sure if even HTML is *that* forgiving. –  Oct 26 '15 at 20:33

2 Answers2

1

changed it to:

'Second part with the charts
    FirstChartPath = ThisWorkbook.Path & "\Current Credit Usage.jpg"
    ChartName = "Current Credit Usage.jpg"
      'add the image in hidden manner, position at 0 will make it hidden
    .Attachments.Add FirstChartPath, olByValue, 0

    'Now add it to the Html body using image name

    'change the src property to 'cid:your image filename'
    'it will be changed to the correct cid when its sent.
    .HTMLBody = .HTMLBody & "<br><B>CURRENT CREDIT USAGE:</B><br>" _
                & "<img src='" & FirstChartPath & "'width='500' height='200'>"
                '& "<br>Best Regards, <br>Sumit</font></span>"

and worked, i was missing one " ' "

Federico Sanchez
  • 145
  • 1
  • 2
  • 12
0

You need to add the image as an attachment and set the PR_ATTACH_CONTENT_ID property: Including Pictures in an Outlook Email

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78