Insert picture into Outlook Mail body excel vba

I am trying to embed a range from a sheet as an image in the body of an Outlook mail. This saves the image correctly, but I only see a blank image in the body of the Outlook mail. 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

      

+3


source to share


1 answer


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

will add and hide it.

.Attachments.Add Fname, 1, 0

      

1

is an Outlook constant olByValue

After adding the image, you should use "cid:FILENAME.jpg"

as below.



try it

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

+3


source







All Articles