1

I'm using a solution from Pasting an Excel range into an email as a picture. How can I paste two ranges into an email?

In my attempt below, the second picture is overwriting the first picture. I would like the second picture to appear after the first one.

 Private Sub generateEmail(rng As Range, rng2 As Range, strName As String)

    'Open a new mail item
    Dim outlookApp As Outlook.Application
    Set outlookApp = CreateObject("Outlook.Application")
    Dim outMail As Outlook.MailItem
    Set outMail = outlookApp.CreateItem(olMailItem)
    With outMail
        .To = strName
        .Subject = "** Please confirm Timesheet by 10:30AM **"
        .Importance = olImportanceHigh
        .Display
    End With


    'Get its Word editor
    Dim wordDoc As Word.Document
    Set wordDoc = outMail.GetInspector.WordEditor

    'To paste as picture
    rng.Copy
    wordDoc.Range.PasteSpecial , , , , wdPasteBitmap
    rng2.Copy
    wordDoc.Range.PasteSpecial , , , , wdPasteBitmap

    outMail.HTMLBody = "Timesheets Submitted by " & strName & "<br>" & _
        Range("DateText") & vbNewLine & outMail.HTMLBody

End Sub
Community
  • 1
  • 1
Shawn H
  • 1,118
  • 3
  • 10
  • 24
  • you'll need to find the end range of the first picture and insert it after it (this is Word VBA syntax you'll need to look up). or you can use [RangeToHTML method](http://www.rondebruin.nl/win/s1/outlook/bmail2.htm) – Scott Holtzman Jul 11 '16 at 19:25
  • fisrt copy and paste both the ranges side by side in a new temp sheet. Then copy the whole range and then paste. Also, instead of using `Word` object, just copy as picture and paste it on a chart area. then export the image from the chart as a file to temp location and insert that file in your e-mail. 1 less dependency this way. :) – cyboashu Jul 11 '16 at 19:35

1 Answers1

0

I was able to accomplish the task by pasting the pictures into two separate paragraphs:

   'To paste as picture
    rng.Copy
    wordDoc.Paragraphs(1).Range.PasteSpecial , , , , wdPasteBitmap
    wordDoc.Content.InsertParagraphAfter
    rng2.Copy
    wordDoc.Paragraphs(2).Range.PasteSpecial , , , , wdPasteBitmap
Shawn H
  • 1,118
  • 3
  • 10
  • 24