将多个excel范围粘贴为同一Outlook电子邮件中的图片

时间:2017-08-04 15:05:42

标签: excel vba excel-vba outlook

以下是我用于复制范围以及打开新的Excel电子邮件的代码。我可以同时复制和粘贴都很好,但我的问题是,当第二张图片粘贴时,它会替换第一张图片,而不是像我需要的那样粘贴在它上面。我做错了什么?

    Private Sub CommandButton4_Click()
'Finds last Row of email report
Dim lRow As Long
Dim lCol As Long


lRow = Cells.Find(What:="*", _
        After:=Range("A1"), _
        LookAt:=xlPart, _
        LookIn:=xlFormulas, _
        SearchOrder:=xlByRows, _
        SearchDirection:=xlPrevious, _
        MatchCase:=False).row

'Copy range of interest
Dim r As Range
Set r = Sheets("Email").Range(Cells(8, "E"), Cells(lRow, "N"))
r.Copy

'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 = ""
    .CC = ""
    .BCC = ""
    .Subject = shift_txtb2.Text & " " & "Finishing Report" & " " & Format(Now(), "MM/DD/YY")
    .HTMLBody = ""
    'Attachments.Add
    .Display
End With

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

''To paste as picture
wordDoc.Range.PasteAndFormat wdChartPicture



Set r = Sheets("Email").Range("P8:T17")
r.Copy
wordDoc.Range.PasteAndFormat wdChartPicture

Unload Me
Sheets(1).Activate
End Sub

1 个答案:

答案 0 :(得分:0)

在粘贴第二个之前放这个:

 wordDoc.Content.InsertParagraphAfter

您也可以尝试:

 wordDoc.Content.TypeParagraph