Results 1 to 20 of 20

Problem with copying charts into html body outlook

Threaded View

katekatebobs Problem with copying charts... 12-12-2013, 08:00 AM
Richard Buttrey Re: Problem with copying... 12-12-2013, 08:03 AM
katekatebobs Re: Problem with copying... 12-12-2013, 08:56 AM
Richard Buttrey Re: Problem with copying... 12-12-2013, 09:15 AM
katekatebobs Re: Problem with copying... 12-12-2013, 10:18 AM
katekatebobs Re: Problem with copying... 12-12-2013, 10:27 AM
Norie Re: Problem with copying... 12-12-2013, 01:00 PM
Richard Buttrey Re: Problem with copying... 12-12-2013, 01:09 PM
katekatebobs Re: Problem with copying... 12-12-2013, 10:13 AM
Richard Buttrey Re: Problem with copying... 12-12-2013, 10:54 AM
katekatebobs Re: Problem with copying... 12-12-2013, 11:00 AM
katekatebobs Re: Problem with copying... 12-12-2013, 11:23 AM
Norie Re: Problem with copying... 12-12-2013, 11:27 AM
katekatebobs Re: Problem with copying... 12-12-2013, 11:29 AM
Norie Re: Problem with copying... 12-12-2013, 11:45 AM
Richard Buttrey Re: Problem with copying... 12-12-2013, 12:28 PM
Norie Re: Problem with copying... 12-12-2013, 12:36 PM
Richard Buttrey Re: Problem with copying... 12-12-2013, 12:47 PM
katekatebobs Re: Problem with copying... 12-13-2013, 01:56 PM
Richard Buttrey Re: Problem with copying... 12-13-2013, 02:16 PM
  1. #1
    Registered User
    Join Date
    12-12-2013
    Location
    Manchester
    MS-Off Ver
    Excel 2003
    Posts
    9

    Problem with copying charts into html body outlook

    Hello

    I am attempting to copy one active sheet into html body outlook message.

    I have the following code, which is adding the attachments however my charts still do not appear.

    I am attempting to add one chart for now, but once complete will need to add all 5 from the page.

    Any help with the code would be much, much appreciated.

    Thank you


    Sub Mail_Sheet_Outlook_Body1650()
    
        Dim Rng As Range
        Dim OutApp As Object
        Dim OutMail As Object
        Dim cell As Range
        Dim strto As String
        Dim Fname1 As String
        Dim FnameRoot As String
       
        Const ForReading As Long = 1
        Const olMailItem = 0
        Const olFormatHTML = 2
        Const UseDefault As Long = -2
            
        
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With
               
        FnameRoot = "C:\Users\kroberts\desktop"
        Fname1 = FnameRoot & "chart1.gif"
        With ActiveWorkbook.Worksheets("EMAILSHEET").ChartObjects("Chart 1")
        .Activate
        .Chart.Export Filename:=Fname1, FilterName:="GIF"
        End With
        
        Set Rng = Sheets("EMAILSHEET").UsedRange
        
          For Each cell In ThisWorkbook.Sheets("ADDRESSES").Range("A3:A10")
            If cell.Value Like "?*@?*.?*" Then
                strto = strto & cell.Value & ";"
            
            End If
        Next cell
        If Len(strto) > 0 Then strto = Left(strto, Len(strto) - 1)
        
        On Error Resume Next
     
        
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
              
        With OutMail
            .attachments.Add Fname1
            .Save
            .To = strto
            .CC = ""
            .BCC = ""
            .Subject = "MARKET UPDATE 1650"
            .BodyFormat = olFormatHTML
            .HTMLBody = RangetoHTML(Rng) & "<IMG src=cid:desktopchart1.gif></img>"
            .Send
            End With
        On Error GoTo 0
        
            
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    
    
    Function RangetoHTML(Rng As Range)
    
        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
             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
    Last edited by katekatebobs; 12-12-2013 at 08:54 AM. Reason: TO COMPLY WITH RULES

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Conditional formatting not copying over correctly into body of HTML email
    By seaottr in forum Excel Programming / VBA / Macros
    Replies: 29
    Last Post: 04-10-2017, 01:01 PM
  2. Looping through Filter and then copying the data so I can paste or put into outlook body
    By Josh_123456 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-28-2016, 12:12 AM
  3. Macro to copy charts and data from excel to outlook body
    By aspirant in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-22-2013, 03:51 AM
  4. Send e-mail with image on body (.html) on e-mail manager <> outlook
    By mariotnc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-05-2012, 09:28 PM
  5. Copying Excel worksheet in Outlook email body
    By xatomicx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-30-2010, 01:38 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1