Solved

How to include charts in CDO email Body

Posted on 2009-07-02
2
686 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

757 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

18 Experts available now in Live!

Get 1:1 Help Now