0

I have use the below macro to copy graph into picture and text to outlook to send out. I have set the emails to myself and 2 other recipient.

I am manage to see those graph, however the other 2 recipient cannot see the graph. they see it as a cross (X) in a box. my temp files isn't deleted so I don't know why they see cross in the image of the graph

Sub SendChart_As_Body_UsingOutlook()

Dim rng As Range
Dim olApp As Object
Dim NewMail As Object
Dim ChartName As String
Dim ChartName1 As String

Set rng = Range("A1:AQ45").SpecialCells(xlCellTypeVisible)
Set olApp = CreateObject("Outlook.Application")


'fill in the file path/name of the gif file
ChartName = Environ$("temp") & "\Chart.gif"
ChartName1 = Environ$("temp") & "\Chart1.gif"

ActiveWorkbook.Worksheets("feb 18").ChartObjects("Chart 1").Chart.Export _
Filename:=ChartName, FilterName:="JPEG"
ActiveWorkbook.Worksheets("feb 18").ChartObjects("Chart 2").Chart.Export _
Filename:=ChartName1, FilterName:="JPEG"

' Create a new mail message item.
Set NewMail = olApp.CreateItem(0)
With NewMail
    .Subject = "copy graph and text - Auto"
    .To = "meme@xxx.com; reciep1@xxx.com; reciept2@xxx.com"

    .HTMLBody = RangetoHTML(rng) & "<img src=" & "'" & ChartName1 & "'>" & "<img src=" & "'" & ChartName & "'>"
    .send
End With

'Now delete the chart image from the temp folder
'Kill ChartName

'Release memory.
Set olApp = Nothing
Set NewMail = Nothing

End Sub
braX
  • 11,506
  • 5
  • 20
  • 33
Sypnoticjr
  • 41
  • 1
  • 2
  • 6
  • Can you share the spreadsheet? – 0m3r Feb 28 '18 at 20:46
  • @0m3r - FYI, don't bother, this guy's been flagged to mod for obvious plagiarism while having the nerve to claim the code is his own. His question history shows we're all completing a project for him. – ashleedawg Mar 01 '18 at 04:45

2 Answers2

0

The problem is that you're just creating a link to the image on your PC, not embedding the image in the e-mail. You need to include an Attachments.Add line in your VBA. See embedded Images in html email from Excel VBA .

Tevildo
  • 340
  • 2
  • 11
  • Hi. Thanks. I will try. My table of cells which uses rangetohtml sometimes also doesnt appear in the email i send out. Is it the same issue? – Sypnoticjr Feb 27 '18 at 13:04
  • Hi. I tried attachment.add but it came out as cross too. Anyone can help? – Sypnoticjr Feb 28 '18 at 01:18
  • Hi. Now my chart don even show in the send item when i use another laptop to send. When .display it will work, i see the graph. When i .send i don see my graph in sent item and inbox. Anyone can help me – Sypnoticjr Feb 28 '18 at 09:41
0

Try something like this

With NewMail
    .Subject = "copy graph and text - Auto"
    .To = "meme@xxx.com; reciep1@xxx.com; reciept2@xxx.com"
    .Attachments.Add ChartName, olByValue, 0
    .Attachments.Add ChartName1, olByValue, 0
    .HTMLBody = "<body>" & RangetoHTML(Rng) & _
                "<img src=" & "'" & ChartName1 & "'>" & _
                "<img src=" & "'" & ChartName & "'> </body>"
    .Display
End With

Here is another examples using Word object

https://stackoverflow.com/a/48897439/4539709

https://stackoverflow.com/a/40052843/4539709

0m3r
  • 12,286
  • 15
  • 35
  • 71