VBA: Email chart as HTML instead of JPG attachment

NeoSez

Board Regular
Joined
Aug 14, 2020
Messages
246
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I am stuck on this snippet to create the Excel chart and paste it into an email body as as HTML instead of as a jpg as many people receive the email can not view the jpg.
I tried to change this to
VBA Code:
[B].htmlbody = body & _HTML[/B]
but it doesn't work.
What am I missing?


VBA Code:
'----Build Chart---------------------
Worksheets("File1").Range("A4").Value = SAMPLE
Call createChart("File1", "B3:N23", File2)
tempFilename2 = TempFilePath & File2 & ".jpg"
'------------------------------------

'----FILE NAME CHECKS----------------
'MsgBox tempFilename1
'MsgBox tempFilename2
'MsgBox File2 & ".jpg"
'------------------------------------

'----EMAIL FILE TO SAMPLE------------
Dim OutApp As Object
Dim OutMail As Object
    
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
   On Error Resume Next
With OutMail

.display
.To = toemail
.CC = ccemail
.subject = subject
.Attachments.Add tempFilename1
.Attachments.Add tempFilename2, 1, 1
[B].htmlbody = body & _
                "<br><br><img src=""cid:" & File2 & ".jpg"" height=450 width=650>" & .htmlbody[/B]

.display
'.Send
End With

 On Error GoTo 0
Set OutApp = Nothing
Set OutMail = Nothing
toemail = ""
ccemail = ""
subject = ""
body = ""
'------------------------------------

'----DELETE THE FILE-----------------
Kill tempFilename1
Kill tempFilename2
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
A .jpg is an image file. HTML is not. The format of the e-mail can be in HTML, however the image itself cannot. You can convert images to various image file types, like .png, which may work better for e-mail. (Not sure you can do that within Excel, though.)
 
Upvote 0
Thanks, but I would prefer to paste the chart as HTML, and the email also contains text.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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