I Can Attach Chart To Email. But How To Insert Image In Body?

aedctalk

Board Regular
Joined
Oct 9, 2010
Messages
156
So the below code works great for attaching a chart image into my email.

However I'd prefer the image shows up in the body. Rather than as an attachment.

If my email allows HTML (or maybe it doesnt need to) is there a way to insert the image into my .BODY ?

I've tried .Body = Fname without any luck ...


Thanks!!! :)


Code:
Sub SaveSend_Embedded_Chart()


    Dim OutApp As Object
    Dim OutMail As Object
    Dim Fname As String

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

    'fill in the file path/name of the gif file
    Fname = Environ$("temp") & "\Theatre_Charts.gif"

    'if you hold down the CTRL key when you select the chart
    'in 2000-2010 you see the name in the name box(formula bar)
    ActiveWorkbook.Worksheets("Home").ChartObjects("Chart 299").Chart.Export _
            Filename:=Fname, FilterName:="GIF"

    On Error Resume Next
    With OutMail
        .To = "a@gmail.com"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = "Station Inventory Charts"
        .Attachments.Add Fname
        .Display   'or use .Display
    End With
    On Error GoTo 0

    Kill Fname
    Set OutMail = Nothing
    Set OutApp = Nothing

    
    
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
If my email allows HTML (or maybe it doesnt need to) is there a way to insert the image into my .BODY ?

I've tried .Body = Fname without any luck ...
Use .HTMLbody instead of .Body and specify the image file name in an < img > tag, like this:
Code:
.HTMLbody = "< p >Example chart:< /p >< img src='" & Fname & "' >"
Note - I've had to add a space after each < and before each > character to prevent the forum from rendering the code as HTML. You should remove these spaces in your code.
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,348
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top