我试图弄清楚如何将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
答案 0 :(得分:0)
通过调用以下代码行:
ActiveSheet.Paste
将图像粘贴到Excel工作表上,而不是Outlook中。
您可以尝试使用Word对象模型将图像粘贴到邮件项目中。 Outlook对象模型为工作项主体提供了三种主要方式:
您可以在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。