简体   繁体   English

将Excel图表复制到Outlook邮件

[英]Copy Excel chart to Outlook mail message

I have email addresses in column A, and a chart object in the same sheet. 我在A列中有电子邮件地址,并且在同一工作表中有一个图表对象。

For each email address, I want to create a new mail in Outlook and paste the Excel chart into the email body. 对于每个电子邮件地址,我想在Outlook中创建一个新邮件并将Excel图表粘贴到电子邮件正文中。

The problem with my attempt (below) is that the chart does not get pasted into the mail body. 我的尝试问题(如下)是图表未粘贴到邮件正文中。 How do I fix this? 我该如何解决?

This my code: 这是我的代码:

Sub smail()        
    Dim r As Integer
    Dim o As Outlook.Application
    Dim m As Outlook.MailItem
    Set o = New Outlook.Application
    r = 1
    Do While Cells(r, 1) <> ""
        Set m = o.CreateItem(olMailItem)
        m.To = Cells(r, 1)
        m.CC = "xyz@anc.com"
        m.BCC = "abc@xyz.com"
        m.Subject = "Test"
        ActiveChart.ChartArea.Copy
        Set wEditor = o.ActiveInspector.WordEditor
        'm.Body = Paste
        wEditor.Application.Selection.Paste

        m.Send
        r = r + 1
        Set m = Nothing
    Loop
End Sub

I think the problem with this line 我认为这条线有问题

wEditor.Application.Selection.Paste

is that nothing is selected, ie .Selection returns Nothing , as long as the message is not visible. 是什么都没有选择,即.Selection返回Nothing ,只要消息不可见。 To solve this, make it visible before pasting: 要解决此问题,请在粘贴之前使其可见:

m.Display

That worked for me. 那对我有用。

Also, you should always declare all your variables using Dim , including wEditor : 另外,您应该始终使用Dim声明所有变量,包括wEditor

Dim wEditor As Word.Document

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM