fredlo2010
06-16-2014, 12:34 PM
Hello,
I am trying to write a code that creates a message and then includes a certain workbook as an attachment. Everything works except my attachment file is not added to the email. Any ideas ? I have check and the file does exist.
Sub SendEmail()
'Object Variables
Dim oOutlookApp As Object
Dim oItem As Object
Dim strBody As String
On Error Resume Next
'Start Outlook if it isn't running
Set oOutlookApp = CreateObject("Outlook.Application")
'Create a new message
Set oItem = oOutlookApp.CreateItem(0) 'olMailItem
'DECLARE VARIABLES FOR BODY
strBody = "<p>Hello,</p>"
strBody = strBody & "<p>Please find attached file.<p>"
strBody = strBody & "<p>Please review before sending. If you have any questions please let me know.</p>"
strBody = strBody & vbNewLine
strBody = strBody & "Thanks"
With oItem
.Subject = "Hello There"
.To = "me@gmai.com"
.Display
.HTMLBody = "<font size=""3.8"" <p>" & strBody & "</font>" & oItem.HTMLBody
.Attachments.Add Source:="C:\Users\alo\Downloads\New.xlsx", Type:=1, _
DisplayName:="Document as attachment" 'olByValue
End With
End Sub
Thanks
I am trying to write a code that creates a message and then includes a certain workbook as an attachment. Everything works except my attachment file is not added to the email. Any ideas ? I have check and the file does exist.
Sub SendEmail()
'Object Variables
Dim oOutlookApp As Object
Dim oItem As Object
Dim strBody As String
On Error Resume Next
'Start Outlook if it isn't running
Set oOutlookApp = CreateObject("Outlook.Application")
'Create a new message
Set oItem = oOutlookApp.CreateItem(0) 'olMailItem
'DECLARE VARIABLES FOR BODY
strBody = "<p>Hello,</p>"
strBody = strBody & "<p>Please find attached file.<p>"
strBody = strBody & "<p>Please review before sending. If you have any questions please let me know.</p>"
strBody = strBody & vbNewLine
strBody = strBody & "Thanks"
With oItem
.Subject = "Hello There"
.To = "me@gmai.com"
.Display
.HTMLBody = "<font size=""3.8"" <p>" & strBody & "</font>" & oItem.HTMLBody
.Attachments.Add Source:="C:\Users\alo\Downloads\New.xlsx", Type:=1, _
DisplayName:="Document as attachment" 'olByValue
End With
End Sub
Thanks