Hi,
I'm using the below code to convert the range to JPG and email. However, if I put .send than the blank email goes out but when I put .display than email is fine. Please can you help me that where I'm going wrong as I want email to go out automatically rather than manually clicking send button.
Thank you
I'm using the below code to convert the range to JPG and email. However, if I put .send than the blank email goes out but when I put .display than email is fine. Please can you help me that where I'm going wrong as I want email to go out automatically rather than manually clicking send button.
Thank you
VBA Code:
Sub jpgpdfrtw()
Dim OutApp As Object
Dim OutMail As Object
Dim table As Range
Dim pic As Picture
Dim ws As Worksheet
Dim wordDoc
Dim a As String, b As String, c1 As String, c2 As String, c3 As String, d As String
Dim IsCreated As Boolean
Dim i As Long
Dim j As Long
Dim PdfFile As String, Title As String
Dim fName As String
Dim OutlApp As Object
Dim oItem As Object
Const olMailItem As Long = 0
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Set ws = ThisWorkbook.Sheets("ABC")
Set table = ws.Range("A1:J36")
ws.Activate
table.CopyPicture
Set pic = ws.Pictures.Paste
pic.Cut
On Error Resume Next
With OutMail
.To = Range("N3").Value
.CC = Range("N5").Value & "; " & Range("O10").Value
.Subject = "ABC" & " " & ActiveSheet.Range("B7").Value
.send
Set wordDoc = OutMail.GetInspector.WordEditor
With wordDoc.Range
.PasteandFormat wdChartPicture
.insertParagraphAfter
.insertParagraphAfter
.InsertAfter "Many thanks,"
.insertParagraphAfter
.InsertAfter
End With
.htmlbody = "<BODY style = font-size:11pt; font-family:Calibri >" & _
"Hi, <p> ABCDEFGH. <p>" & .htmlbody
On Error Resume Next
Application.Visible = True
If Err Then
MsgBox "E-mail was not sent", vbExclamation
Else
MsgBox "Email sent", vbInformation
End If
On Error GoTo 0
Set OutApp = Nothing
Set OutMail = Nothing
Application.CutCopyMode = False
End With
End Sub