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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44869790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 10:52:03  来源:igfitidea点击:

Embed picture in outlook mail body excel vba

excelvbaexcel-vbaoutlook

提问by Stupid_Intern

I am trying to embed a range from a worksheet as an image in outlook mail body. It's saving the picture correctly but I only see blank image in the outlook mail body. What am I doing wrong here?

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

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

回答by Siddharth Rout

You need to add the image and hide it. The position 0will add and hide it.

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

.Attachments.Add Fname, 1, 0

The 1is the Outlook Constant olByValue

1是 Outlook 常量olByValue

Once you add the image then you have to use "cid:FILENAME.jpg"as shown below.

添加图像后,您必须使用"cid:FILENAME.jpg"如下所示。

Try this

尝试这个

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

Screenshot

截屏

enter image description here

在此处输入图片说明