Pasting two Excel ranges into an email as pictures

时间:2016-07-11 19:20:24

标签: vba excel-vba word-vba excel

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

1 个答案:

答案 0 :(得分: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