将 Excel 中的图片复制到 Outlook 正文

Posted

技术标签:

【中文标题】将 Excel 中的图片复制到 Outlook 正文【英文标题】:Copy picture in Excel to Outlook body 【发布时间】:2015-10-07 20:36:29 【问题描述】:

我想弄清楚如何将 Excel 中的电子表格中的图片放入 Outlook 邮件的正文中。这是我到目前为止所拥有的:

它根据我需要的数据分组创建图片, 将其复制到下面,然后 打开包含我需要的初始消息的邮件

但我不知道如何将创建的两个图像链接到电子邮件正文中。到目前为止,我一直在从每个创建的标签中剪切它们,然后将它们粘贴到正文中。

Sub EmailDashboards()

Dim OutApp As Object
Dim outMail As Object
Sheets("CAM Dashboard Burdened").Select
Range("C1:J47").Select
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
Range("K36").Select
ActiveSheet.Paste

Sheets("CAM Dashboard Direct").Select
Range("C1:J47").Select
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
Range("K36").Select
ActiveSheet.Paste

Sheets("CAM Dashboard Burdened").Select
Range("K36").Select

With Application
    .EnableEvents = False
    .ScreenUpdating = False
End With

Set OutApp = CreateObject("Outlook.Application")
Set outMail = OutApp.CreateItem(0)

With outMail
    .To = ""
    .CC = ""
    .BCC = ""
    .Subject = "CCM EV Dashboard"
    .Body = "Here are the latest Burdened and Direct EV Dashboards for your area: "
    .Display
End With

On Error GoTo 0

With Application
    .EnableEvents = True
    .ScreenUpdating = True
End With

Set outMail = Nothing
Set OutApp = Nothing

End Sub

【问题讨论】:

阅读此http://excel-macro.tutorialhorizon.com/excel-vba-send-unique-images-embedded-to-mail-body-with-every-mail-from-ms-outlook-using-excel/ 【参考方案1】:

通过调用以下代码行:

 ActiveSheet.Paste

您将图像粘贴到 Excel 工作表上,而不是 Outlook 中。

您可以尝试使用 Word 对象模型将图像粘贴到邮件项目中。 Outlook 对象模型为工作项正文提供了三种主要方式:

    Body - 表示 Outlook 项目的明文正文的字符串。 htmlBody - 表示指定项的 HTML 正文的字符串。 Word editor - 正在显示的消息的 Microsoft Word 文档对象模型。 Inspector 类的 WordEditor 属性从 Word 对象模型返回 Document 类的一个实例,您可以使用它来设置消息正文。

您可以在Chapter 17: Working with Item Bodies 中阅读有关所有这些方式的更多信息。

Selection 类的Paste 方法将剪贴板的内容插入到指定的选择。

您还可以将图像附加到邮件项,将它们标记为隐藏设置适当的低级属性,并在正文的 HTML 标记中提及它们。

  Attachment attachment = newMail.Attachments.Add(
 @"E:\Pictures\image001.jpg"
, OlAttachmentType.olEmbeddeditem
, null
, "Some image display name"
);

string imageCid = "image001.jpg@123";

attachment.PropertyAccessor.SetProperty(
 "http://schemas.microsoft.com/mapi/proptag/0x3712001E"
, imageCid
);

newMail.HTMLBody = String.Format(
 "<body><img src=\"cid:0\"></body>"
, imageCid
);

请参阅how to embed image in html body in c# into outlook mail 了解更多信息。

【讨论】:

以上是关于将 Excel 中的图片复制到 Outlook 正文的主要内容,如果未能解决你的问题,请参考以下文章

在 Excel 中使用 VBA,如何在 Outlook 中粘贴表格然后将表格转换为文本?

将图片从 Excel 形状复制到 VBA 中的图像对象

使用 VBA 宏选择和复制 Outlook 电子邮件正文

将Excel范围粘贴到Outlook电子邮件正文

Outlook不能预览和打开Excel文件:

从 Excel 打开 Word 文档并将内容粘贴到 Outlook 邮件的正文