首页 > 解决方案 > VBA Excel - 在 Outlook 邮件正文中粘贴图表(不是图像)

问题描述

我正在尝试使用 Excel VBA 通过 Outlook 将图表粘贴到新电子邮件中。它不能作为图像发送,因为它失去了太多的分辨率。我需要它完成的方式就像我手动做的那样,只是复制和粘贴(ctrl + c,ctrl + v):

在此处输入图像描述

我的代码如下:

ThisWorkbook.Worksheets("Somatório_bacias").ChartObjects(1).Copy

'Envia o e-mail
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

With OutMail
   .To = "myemail@gmail.com"
   .Cc = ""
   .Subject = ""

   'Chart part goes around here

   .send   '.send or use .Display
End With

有人有不使用图像的解决方案吗?

标签: excelvbachartsoutlook

解决方案


您可以使用正在显示的消息的 Word 文档对象模型。

With OutMail
    'Display message to allow access to the Word Document Object Model
    .Display
   .To = "myemail@gmail.com"
   .Cc = ""
   .Subject = ""
   'Access the Word Document Object Module
    With .GetInspector.WordEditor
        'Go to the end of the email (optional)
        .Application.Selection.EndKey Unit:=6 'wdStory
        'Add a new line (optional)
        .Application.Selection.TypeParagraph
        'Add a new line (optional)
        .Application.Selection.TypeParagraph
        'Paste the chart into the body of the email
        .Application.Selection.Paste
    End With
   .send
End With

推荐阅读