2015-10-26 77 views
1

嵌入式图像我试图建立一个自动电子邮件,同时使用HTML代码的文本和图像(Excel中的图表)。这是我第一次写这种代码,所以我抬头看看,并合并了我在网上找到的一些代码。这是我迄今为止的形象:嵌入式图像从Excel VBA

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”中的形象说法链接的图像无法显示“该文件可能已被移动,重命名或确认链接指向正确的文件和位置“任何人都可以发现错误?

+0

不应该有源文件和宽度之间的空间。不知道,即使HTML * * *宽容。 – Jeeped

回答

0

将其改为:

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

和工作,我错过了一个“'”