[英]How to send a shape object from Excel in the body of an Email?
我正在努力尝试在宏中执行这一(看似)简单的步骤。 我有一个Excel形状对象,我要复制该对象,然后将其粘贴到Outlook邮件项目中。 形状对象实际上是使用Excel的“相机工具”的产品。 我所做的就是创建了一个图表,需要将其翻转90度才能查看。 摄像头工具使这一过程变得简单。 我现在唯一的问题是将这张图片形状粘贴到Outlook项目中。 有什么建议吗?
到目前为止,这是我的代码:
Sub emailer()
Dim wb As Workbook
Dim ws As Worksheet
Dim p As Shape
Dim o As Outlook.Application
Dim om As Outlook.MailItem
Dim rec As Outlook.Recipient
Dim recs As Outlook.Recipients
'create the outlook session
Set o = CreateObject("Outlook.Application")
'create the message
Set om = o.CreateItem(olMailItem)
Set recs = om.Recipients
Set rec = recs.Add("email@email.com")
rec.Type = 1
Set wb = ActiveWorkbook
Set ws = ActiveWorkbook.Worksheets("Chart_Pic")
Set p = ws.Shapes("Picture 2")
p.CopyPicture
With om
.SentOnBehalfOfName = "email@email.com"
.Subject = "Subject"
.HTMLBody = "This is a test" & vbCrLf & vbCrLf & [where I want the shape to go]
For Each rec In om.Recipients
rec.Resolve
Next
om.Send
End With
Set o = Nothing
您可以使用剪贴板复制/粘贴图片。 但是为此,您需要一个可以处理剪贴板的Outlook邮件编辑器。 以WordEditor为例。
例:
Sub emailer()
Set oOlApp = CreateObject("Outlook.Application")
Set oOlMItem = oOlApp.CreateItem(olMailItem)
Set oWB = ActiveWorkbook
Set oWS = ActiveWorkbook.Worksheets("Chart_Pic")
Set oPic = oWS.Shapes("Picture 2")
oPic.CopyPicture ' oPic is now in Clipboard
With oOlMItem
.Display
.To = "email@email.com"
.Subject = "Subject"
Set oOlInsp = .GetInspector
Set oWdDoc = oOlInsp.WordEditor ' get Word Document from the MailBody
Set oWdContent = oWdDoc.Content
oWdContent.InsertParagraphBefore
Set oWdRng = oWdDoc.Paragraphs(1).Range
oWdRng.InsertBefore "This is a test"
oWdRng.InsertParagraphAfter
oWdRng.InsertParagraphAfter
Set oWdRng = oWdDoc.Paragraphs(3).Range
oWdRng.Paste ' paste from oPic Clipboard
olFormatHTML = 2
.BodyFormat = olFormatHTML ' change to HTML
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.