在Outlook邮件正文Excel VBA中嵌入图片 [英] Embed picture in outlook mail body excel vba

查看:2042
本文介绍了在Outlook邮件正文Excel VBA中嵌入图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

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将添加并隐藏它.

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

.Attachments.Add Fname, 1, 0

1是Outlook常量olByValue

The 1 is the Outlook Constant olByValue

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

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

尝试一下

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

屏幕截图

这篇关于在Outlook邮件正文Excel VBA中嵌入图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆