通过VBA代码将图片添加到正文邮件-图片空白

时间:2018-11-13 12:19:02

标签: excel vba outlook

根据我的最后一个问题-Add Text & Excel table as picture to email,我曾问过有关通过VBA代码在OutMail中添加图片和正文文本的问题,我找到了解决方案(以下代码),但是由于某种原因,图片没有已添加到正文邮件中(而不是显示错误)-请参见下图。 请您帮忙,我该怎么办才能看到图片。

代码如下:

Sub SendCA_list()

Dim oApp As Object
Set oApp = CreateObject("Outlook.Application")

Dim oMail As Object
Set oMail = oApp.CreateItem(0)

Dim rng As Range
Set rng = Sheet1.Range("Table4[[#All],[Department]:[Status]]")
rng.CopyPicture xlPrinter

Dim chartObj As ChartObject
Set chartObj = Sheet1.ChartObjects.Add(0, 0, rng.Width, rng.Height)

chartObj.Select
chartObj.Chart.Paste
chartObj.Chart.Export ThisWorkbook.Path & "\table.png", "png"
chartObj.Delete

Dim strbody As String
strbody = "<BODY style='font-size:12pt;font-family:HP Simplified'>" & "Hi,<br><br>Please see attached the ISO Internal Audit Report and the open AIs (in the table below)."
strbody = strbody & "<br><img src='cid:table.png'/>"
strbody = strbody & "<br><br>Best Regards,<br>Shira<br><br></BODY>"

With oMail

    .Subject = "Request for CAs - ISO Audit"
    .Attachments.Add ThisWorkbook.Path & "\table.png", 1, 0
    .htmlbody = strbody
    .Display
End With

End Sub

enter image description here

0 个答案:

没有答案