简体   繁体   中英

Embedding image in html email from Excel VBA

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"

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

您需要将图像添加为附件并设置PR_ATTACH_CONTENT_ID属性: 在 Outlook 电子邮件中包含图片

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM