嵌入图片在Outlook邮件正文excel vba

问题描述:

我想嵌入工作表作为图像在Outlook邮件正文的范围。它正确保存图片,但我只在Outlook邮件正文中看到空白图片。我在这里做错了什么?嵌入图片在Outlook邮件正文excel vba

Sub View_Email() 

    tName = Trim(MAIN.Range("tEmail")) 

    If Not tName Like "*@*.*" Then MsgBox "Invalid Email address": Exit Sub 

    Set OutApp = CreateObject("Outlook.Application") 
    Set OutMail = OutApp.CreateItem(0) 

    'File path/name of the gif file 
    Fname = ThisWorkbook.Path & "\Claims.jpg" 

    Set oCht = Charts.Add 

    STAT.Range("A3:G26").CopyPicture xlScreen, xlBitmap 
    With oCht 
     .Paste 
     .Export Filename:=Fname, Filtername:="JPG" 
     '.Delete 
    End With 

    On Error Resume Next 
    With OutMail 
     .To = tName 
     .CC = "" 
     .BCC = "" 
     .Subject = STAT.Range("C1").Value 
     .HTMLBody = "<html><p>Summary of Claim Status.</p>" & _ 
        "<img src=" & Fname & "' height=520 width=750>" 
     .display 
     '.Send 'or use .Display 
    End With 
    On Error GoTo 0 

    'Delete the gif file 
    'Kill Fname 

    Set OutMail = Nothing 
    Set OutApp = Nothing 
End Sub 
+0

调试代码,并检查什么是Fname'的'价值和手动检查文件是否存在。打开文件并检查图表是否已导出 –

+0

@SiddharthRout是的,我确实检查了fname和图片,他们都显得很好,但是outlook主体将图片显示为空白 – newguy

+0

哦,我知道为什么...一刻发布答案 –

您需要添加图像并隐藏它。位置0将添加并隐藏它。

.Attachments.Add Fname, 1, 0 

1是展望恒olByValue

一旦你添加的图像,然后你必须使用"cid:FILENAME.jpg",如下图所示。

试试这个

With OutMail 
    .To = tName 
    .CC = "" 
    .BCC = "" 
    .Subject = STAT.Range("C1").Value 
    .Attachments.Add Fname, 1, 0 
    .HTMLBody = "<html><p>Summary of Claim Status.</p>" & _ 
       "<img src=" & "cid:Claims.jpg" & "height=520 width=750>" 
    .Display 
End With 

截图

enter image description here

+1

非常感谢它完美地工作。 – newguy