vba 将 Excel 图表复制到 Outlook 邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25603864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copy Excel chart to Outlook mail message
提问by Ravi Kalidosan
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 = "[email protected]"
m.BCC = "[email protected]"
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
回答by Jean-Fran?ois Corbett
I think the problem with this line
我认为这条线的问题
wEditor.Application.Selection.Paste
is that nothing is selected, i.e. .Selection
returns Nothing
, as long as the message is not visible. To solve this, make it visible before pasting:
是什么都没有选择,即.Selection
返回Nothing
,只要消息不可见。要解决此问题,请在粘贴前使其可见:
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