VBA电子邮件,粘贴图表和正文中的文本

时间:2015-06-19 17:40:49

标签: excel vba email excel-vba outlook

以下代码的目标是将选定的图表粘贴到下面我的文本中的电子邮件正文中。但是,它会继续将其粘贴到我的文本上方。如何更改它以使其粘贴在下面?谢谢!

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
    .CC = "xyz@anc.com"
    .BCC = "abc@xyz.com"
    .Subject = "Test"
    .Body = "Dear" & "Macro "

    ActiveSheet.Range("P36:X46").Copy
    Set wEditor = OutApp.ActiveInspector.WordEditor

    wEditor.Application.Selection.Paste

.display

1 个答案:

答案 0 :(得分:9)

更改选择的开始和结束。添加额外的换行符也可能是一个好主意。您还应该使用MailItem.GetInspector而不是Application.ActiveInspector,因为消息尚未显示。

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
    .CC = "xyz@anc.com"
    .BCC = "abc@xyz.com"
    .Subject = "Test"
    .Body = "Dear" & "Macro " & vbCrLf

    ActiveSheet.Range("P36:X46").Copy
    set vInspector = OutMail.GetInspector
    Set wEditor = vInspector.WordEditor

    wEditor.Application.Selection.Start = Len(.Body)
    wEditor.Application.Selection.End = wEditor.Application.Selection.Start

    wEditor.Application.Selection.Paste

.display