这里有一个问题,关于如何使用VBA将图表插入Outlook电子邮件的正文中,我已经起草了一个答案但已经消失了。
我认为没有Sendkeys会有一种更简单的方法,但看起来我错了!
无论如何,我想我会发布答案,以防原始海报仍在寻找,或者是否有其他人需要,或者即使有人能提出更好的解决方案。
答案 0 :(得分:0)
Sub charttoemail()
Dim myOutlook As Outlook.Application
Dim myMessage As Outlook.MailItem
On Error GoTo Handler
Set myOutlook = GetObject(, "Outlook.Application")
Set myMessage = myOutlook.CreateItem(olMailItem)
'Copy the chart
ActiveChart.ChartArea.Copy
With myMessage
.To = "steven@test.com"
.Subject = "Here's your chart"
.BodyFormat = olFormatHTML
.Body = "Hi, Here's your chart" & vbCr & vbCr
'Display to view the email and send to automatically fire it off
.Display
'.Send
End With
'First key moves cursor to end of email and the second
'pastes the copied chart
SendKeys "^{END}"
SendKeys "^({v})", True
Set myOutlook = Nothing
Set myMessage = Nothing
Exit Sub
'If Outlook is not open, open it
Handler:
Set myOutlook = CreateObject("Outlook.Application")
Err.Clear
Resume Next
End Sub