VBA Email with pasted chart and text in body

你离开我真会死。 提交于 2019-12-30 19:47:12

问题


The goal of the following code is to paste the selected chart into the email body below my text. However, it continues to paste it above my text. How can I change it to make it paste below? Thanks!

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:


Change the selection start and end. Adding an extra line break might also be a good idea. You should also use MailItem.GetInspector instead of Application.ActiveInspector since the message is not yet displayed.

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


来源:https://stackoverflow.com/questions/30944202/vba-email-with-pasted-chart-and-text-in-body

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