I have found the code to paste a chart from excel to outlook here on stack over flow.
This works fine but The issue is the outlook creating new email and pasting procedure is getting displayed on the screen. Is there any way to disable or make this to background?
Sub Mail_Range()
Dim Sht As Excel.Worksheet
Set Sht = ThisWorkbook.ActiveSheet
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Dim rng As Range
Set rng = Sht.Range("A5:W20")
rng.Copy
Dim OutApp As Object
Set OutApp = CreateObject("Outlook.Application")
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
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 = "xxx.xxx.com"
.CC = ""
.Subject = Sht.Range("A5").Value
.GetInspector
wEditor.Paragraphs(1).Range.Text = "This is an auto generated e-mail" & vbCr
wEditor.Paragraphs(2).Range.Paste
.send
End With
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Application.CutCopyMode = False
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
When I'm using
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
after outlook application creation my pasting code doesn't work. Im getting an email with no content.