+ Reply to Thread
Results 1 to 3 of 3

Problem sending images in email body

Hybrid View

sharky12345 Problem sending images in... 01-21-2012, 01:12 AM
Ron Coderre Re: Problem sending images in... 01-21-2012, 01:36 AM
sharky12345 Re: Problem sending images in... 01-21-2012, 07:25 AM
  1. #1
    Registered User
    Join Date
    08-23-2010
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    7

    Problem sending images in email body

    Guys,

    The attached code, (courtesy of Ron de Bruin), attachs the named range into the body of an email message but I have a problem.

    It is not including 2 pictures which are crucial to be included.

    How can I achieve this?

    Sub Mail_Selection_Range_Outlook_Body()
    ' Don't forget to copy the function RangetoHTML in the module.
    ' Working in Office 2000-2010
     Dim rng As Range
     Dim OutApp As Object
     Dim OutMail As Object
     Set rng = Nothing
     On Error Resume Next
     'Only the visible cells in the selection
     'You can also use a range if you want
     Set rng = Sheets("Duties").Range("A1:Q21").SpecialCells(xlCellTypeVisible)
     On Error GoTo 0
     If rng Is Nothing Then
         MsgBox "The selection is not a range or the sheet is protected" & _
                vbNewLine & "please correct and try again.", vbOKOnly
         Exit Sub
     End If
     With Application
         .EnableEvents = False
         .ScreenUpdating = False
     End With
     Set OutApp = CreateObject("Outlook.Application")
     Set OutMail = OutApp.CreateItem(0)
     On Error Resume Next
     With OutMail
         .To = ""
         .CC = ""
         .BCC = ""
         .Subject = Sheets("Duties").Range("H2") & " - " & Sheets("Duties").Range("M2") & " Shift" & " Duties"
         .HTMLBody = RangetoHTML(rng)
         .Display
     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)
    ' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, and Outlook 2010.
     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 workbook to receive the data.
     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 an .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 the RangetoHTML subroutine.
     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.
     Kill TempFile
    
     Set ts = Nothing
     Set fso = Nothing
     Set TempWB = Nothing
    End Function

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Problem sending images in email body

    You're new here so you REALLY need to read the forum rules for this moderated forum.
    You'll notice there's a rule requiring you to post a link to any other forums where you post the same question. The link allows the talented folks at Excel Forum to keep track of the progress at the other forum(s)...and stop trying to assist you once your issue is resolve.

    Since you ARE new, I'll post the link for you...(this time)
    http://www.mrexcel.com/forum/showthread.php?t=607139
    Last edited by Ron Coderre; 01-21-2012 at 10:01 AM.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Registered User
    Join Date
    08-23-2010
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Problem sending images in email body

    Noted - and I will consider myself told!

    However, the other post which you have kindly attached has no replies so I guess I shall just shelve this idea.

    Thanks anyway!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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