2015-10-26 53 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>" 

和工作,我錯過了一個「'」