我在A列中有电子邮件地址,在同一张表中有图表对象 .
对于每个电子邮件地址,我想在Outlook中创建一个新邮件,并将Excel图表粘贴到电子邮件正文中 .
我的尝试(下面)的问题是图表没有粘贴到邮件正文中 . 我该如何解决?
这是我的代码:
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
1 回答
我认为这条线的问题
是没有选择任何内容,即
.Selection
返回Nothing
,只要该消息不可见 . 要解决此问题,请在粘贴之前将其显示为:这对我有用 .
此外,您应该始终使用
Dim
声明所有变量,包括wEditor
: