Embed picture in outlook mail body excel vba

0 votes

I'm attempting to insert a worksheet's range as an image in the body of an outlook mail message. Although the picture is correctly saved, the outlook mail body just contains a blank image. Why am I doing this wrong?

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
Dec 16, 2022 in Others by Kithuzzz
• 38,000 points
5,499 views

1 answer to this question.

0 votes

The image needs to be added and then hidden. It will be added and hidden at position 0.

.Attachments.Add Fname, 1, 0

The 1 is the Outlook Constant olByValue

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

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

answered Dec 16, 2022 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

Language independent way to get "My Documents" folder in VBA Excel 2003

 Hello :)  This code may help you in your ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,690 points
834 views
0 votes
1 answer

Runtime error 438 while importing data in excel from secured website using VBA

Replace With ieDoc.forms(0) .userType.Value = "1" ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 63,600 points
915 views
0 votes
1 answer

How to print an Excel Sheet using VBA with Nitro PDF Creator in Excel 2016

you can use the built-in excel facilities ...READ MORE

answered Sep 24, 2022 in Others by narikkadan
• 63,600 points
1,402 views
0 votes
1 answer

Convert image (jpg) to base64 in Excel VBA?

Heres a function. Can't remember where I ...READ MORE

answered Sep 27, 2022 in Others by narikkadan
• 63,600 points
3,147 views
0 votes
1 answer

VBA How to extract the date and time of arrival of a answered email

Use MailItem.ReceivedTime property. I hope this helps you ...READ MORE

answered Jan 9, 2023 in Others by narikkadan
• 63,600 points
2,916 views
0 votes
1 answer

Error populating email body from word documents

There is no need to use late ...READ MORE

answered Jan 15, 2023 in Others by narikkadan
• 63,600 points
1,571 views
0 votes
1 answer

Export All appointments and meetings (including recurring meetings) Excel VBA

However, when I use the code above ...READ MORE

answered Feb 13, 2023 in Others by narikkadan
• 63,600 points
1,724 views
0 votes
1 answer

Excel VBA creating a new Outlook appointment results in a cancelled appointment

Because an inappropriate sender will be used, ...READ MORE

answered Feb 14, 2023 in Others by Kithuzzz
• 38,000 points
897 views
0 votes
1 answer
0 votes
1 answer

Excel-VBA - How to identify Target range (more than 1 cell) is deleted in a Worksheet_Change function?

You misunderstand the purpose of the function ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 63,600 points
3,768 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP