Solved

How to include charts in CDO email Body

Posted on 2009-07-02
2
692 Views
Last Modified: 2012-05-07
I have been playing around with Ron de Bruin's code for the RangetoHTML function and I need to see if I can modify this solution to allow the additions of embedded charts and send in the body of a CDO email.

The other end of this is his macro that I have set to select Set rng = ActiveSheet.UsedRange.  What I have is a sheet that has a handful of simple tables and then a couple of embedded charts that all need to go in the body of an email.

Any thoughts how to add some code so that these embedded charts get picked up as part of "rng" and are sent in the email body?
Function RangetoHTML(rng As Range)

' Changed by Ron de Bruin 28-Oct-2006

' Working in Office 2000-2007

    Dim fso As Object

    Dim ts As Object

    Dim TempFile As String

    Dim TempWB As Workbook
 

    TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
 

    'Copy the range and create a new workbook to past the data in

    rng.Copy

    Set TempWB = Workbooks.Add(1)

    With TempWB.Sheets(1)

        .Cells(1).PasteSpecial Paste:=8

        .Cells(1).PasteSpecial xlPasteValues, , False, False

        .Cells(1).PasteSpecial xlPasteFormats, , False, False

        .Cells(1).Select

        Application.CutCopyMode = False

        On Error Resume Next

        .DrawingObjects.Visible = True

        .DrawingObjects.Delete

        On Error GoTo 0

    End With
 

    'Publish the sheet to a htm file

    With TempWB.PublishObjects.Add( _

         SourceType:=xlSourceRange, _

         Filename:=TempFile, _

         Sheet:=TempWB.Sheets(1).Name, _

         Source:=TempWB.Sheets(1).UsedRange.Address, _

         HtmlType:=xlHtmlStatic)

        .Publish (True)

    End With
 

    'Read all data from the htm file into RangetoHTML

    Set fso = CreateObject("Scripting.FileSystemObject")

    Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)

    RangetoHTML = ts.readall

    ts.Close

    RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _

                          "align=left x:publishsource=")
 

    'Close TempWB

    TempWB.Close savechanges:=False
 

    'Delete the htm file we used in this function

    Kill TempFile
 

    Set ts = Nothing

    Set fso = Nothing

    Set TempWB = Nothing

End Function

Open in new window

0
Comment
Question by:raynman1972
2 Comments
 
LVL 45

Accepted Solution

by:
patrickab earned 125 total points
ID: 24771202
raynman1972,

I really don't know the answer but can you use something like this

Source:=(TempWB.Sheets(1).UsedRange.Address, TempWB.Sheets(1).Shapes.Range(Array("Chart 1", "Chart 2")))

Patrick
0
 

Expert Comment

by:CarlosLu
ID: 37906984
Hi raynman1972, could you let me know if you get a final solution to send a chart into body area with CDO.. please send me an email to carlos.luzuriaga@dhl.com please
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now