Pasting two Excel ranges into an email as pictures

删除回忆录丶 提交于 2019-12-13 07:28:21

问题


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:


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


来源:https://stackoverflow.com/questions/38314574/pasting-two-excel-ranges-into-an-email-as-pictures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!