从Excel VBA将图像嵌入html电子邮件中 [英] Embedding image in html email from Excel VBA

查看:639
本文介绍了从Excel VBA将图像嵌入html电子邮件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用HTML代码构建同时包含文本和图像(来自Excel的图表)的电子邮件.我合并了在网上找到的代码.

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

我在图像中得到一个"X",表示无法显示链接的图像.

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"

推荐答案

将其更改为:

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

这篇关于从Excel VBA将图像嵌入html电子邮件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆