Paste Chart into Email Body

MarkCBB

Active Member
Joined
Apr 12, 2010
Messages
497
Hi there VBA pros,

I am using excel and Outlook 2010, and I am trying to get the below code to paste a chart from excel to the body of an outlook email.

Code:
Sub test()
Dim olapp As Object
Dim olmail As Object
Set olapp = CreateObject("Outlook.application")
Set olmail = olapp.createitem(0)
    ActiveSheet.ChartObjects("Chart 5").Activate
    ActiveChart.ChartArea.Copy

With olmail
.display
.to = "anyone@wer.co.za"
.body = Paste

End With


End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
The only way I've found of embedding an image into an email is to have the file on disk and use an IMG tag:-
Code:
.HTMLBody = .HTMLBody & "< img src='c:\folder\filename.png'>"
The problem is how to get the chart off the sheet and onto the hard disk!
 
Upvote 0
Exporting chart:
Code:
[COLOR="Blue"]Sub[/COLOR] ExportChart()
    Sheets(1).ChartObjects("Chart 1").Chart.Export "C:\Chart1.png"
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0
Bingo! :)

Does that solve your problem, Mark?
 
Upvote 0
Hi there,

I have just seen that this was replied to.

I am still struggeling.

the mail displays, but instead of the image i just get the tags.

< img src='C:\Users\user\Documents\Chart1.png'>
 
Upvote 0
Remove the space between the < and img in your coding. It's only there in my post to prevent the forum software from interpreting the sequence of characters as an image tag.
 
Upvote 0
Thank you, this is fantastic, I have got it working correctly now. thank you for your assistance.
 
Upvote 0
Hello every one :)

I was working on a similar macro and needed to copy a chart in the activeworkbook to mail body. I tried the codes which are discussed here and it worked fine. But then on the other day when i tried running the same code what i saw is instead of copying the new chart (for which values are changed now) i have the old chart copied into the mail. I am not sure from where it is getting the old chart image and it's no more there in the file. I checked the image which has been imported to my hard disk and that is of the current chart itself. Not sure why and from where it's pulling the old chart image. Please Help.

Many Thanks in advance.

Regards,
Premanshu
 
Upvote 0
Hi,

Actually I am tring to copy the whole sheet to Mail body, which includes the excel cells data plus with charts, means i want to copy the whole sheet data. Please provide your assistance on it.

If I tried copy through range selection, it is not pasting the charts. If i paste the chart only, then the positioning of the chart with the data is not in sync.

Regards,
Lakshay Sharma
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,634
Members
452,934
Latest member
Jdsonne31

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