debxxx1
New Member
Hi Genius people,
If you can help me with below I will be very helpful. Thanks in advance.
I have some Outlook message(.msg) files in my local system. I am trying to send an outlook email where these (.msg) files will be attached. Below is the code which I am using but in the attachments.add line I am getting error "Operation Failed". Please help
If you can help me with below I will be very helpful. Thanks in advance.
I have some Outlook message(.msg) files in my local system. I am trying to send an outlook email where these (.msg) files will be attached. Below is the code which I am using but in the attachments.add line I am getting error "Operation Failed". Please help
Code:
Sub CreateHTMLMail()
Dim olApp As Object
Dim objMail As Object
Dim body, head As String
Dim strfile As String
Set olApp = CreateObject("Outlook.Application")
strfile = "C:/Users/Debasi1N/Documents/abc/Inbox/20180110-0933_External Training.msg"
'Create e-mail item
Set objMail = olApp.CreateItem(0)
head = "<HTML><BODY><P>HiTeam,</P>"
body = body & "<BR /><P>This is a testing email <STRONG>Line check 1</STRONG> line check 2, <STRONG>11/17</STRONG>! Line check 3.</P>"
body = body & "<BR /><P>Please find attached sample email.</P>"
body = body & "<BR /><P>Thanks,<BR />SE Team</P></BODY></HTML>"
With objMail
.subject = wksM.Cells(6, 3)
.To = wksM.Cells(2, 3)
.CC = wksM.Cells(4, 3)
.Attachments.Add = strfile
.BodyFormat = olFormatHTML
.HTMLBody = head & body
.Display
End With
End Sub