简体   繁体   English

在来自 Excel VBA 的 html 电子邮件中嵌入图像

[英]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.我正在尝试使用 HTML 代码构建一个包含文本和图像(来自 Excel 的图表)的电子邮件。 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.我在图像中看到一个“X”,表示无法显示链接的图像。

"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 电子邮件中包含图片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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