将图表从 Excel 粘贴到 Outlook 电子邮件中 [英] Pasting Chart into Outlook Email from Excel
本文介绍了将图表从 Excel 粘贴到 Outlook 电子邮件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在类似页面上尝试了所有其他代码,但未能奏效.
Tried all other codes on similar pages but failed to work.
这是我当前的版本.仅当我当前打开一个新的电子邮件窗口时才有效,而且奇怪的是,我的代码会将 .body 和单元格范围的详细信息粘贴到 2 个单独的新电子邮件窗口中.
This is my current version. Works only if I currently have a new email window open and oddly, my code will paste the .body and cell range details into 2 separate new email windows.
我只希望代码打开一个包含内容 .body 和单元格范围详细信息(包含图表)的新电子邮件窗口.有人知道我的代码哪里出错了吗?
I just want the code to open a new email window with contents .body and cell range details (contains chart). Anybody have any ideas where my code went wrong?
Sub pasting01()
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.TO = "xyz@anc.com"
.CC = "abc@xyz.com"
.Subject = "Test"
.Body = "Dear Mr Lee" & vbNewLine
ActiveSheet.Range("A1:J30").Copy
Set vInspector = OutMail.GetInspector
Set wEditor = vInspector.WordEditor
wEditor.Application.Selection.Start = Len(.Body)
wEditor.Application.Selection.End = wEditor.Application.Selection.Start
wEditor.Application.Selection.Paste
.display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
推荐答案
您的代码有一些错误,请尝试使用 Option Explicit 模块顶部
Option Explicit
Public Sub pasting01()
Dim Sht As Excel.Worksheet
Set Sht = ThisWorkbook.ActiveSheet
Dim rng As Range
Set rng = Sht.Range("A1:J30")
rng.Copy
Dim OutApp As Object
Set OutApp = CreateObject("Outlook.Application")
Dim OutMail As Object
Set OutMail = OutApp.CreateItem(0)
Dim vInspector As Object
Set vInspector = OutMail.GetInspector
Dim wEditor As Object
Set wEditor = vInspector.WordEditor
With OutMail
.TO = "xyz@anc.com"
.CC = "abc@xyz.com"
.Subject = "Test"
.display
wEditor.Paragraphs(1).Range.Text = "Dear Mr Lee" & vbCr
wEditor.Paragraphs(2).Range.Paste
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
这篇关于将图表从 Excel 粘贴到 Outlook 电子邮件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文