PDA

View Full Version : [SOLVED:] Sending OutLook message no Attachment



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

ranman256
06-16-2014, 01:41 PM
Yes it looks fine, but try it this way ,'just in case' of a compatablility issue: (the working code I use)




.Attachments.Add "C:\Users\alo\Downloads\New.xlsx", olByValue, 1

fredlo2010
06-16-2014, 01:53 PM
Thanks a lot for the answer. This code has been working for me in a word macro for years. I implemented it today in excel and it did not work.

...And guess what its working now I have done nothing to it. Crazy.

Well its working now. I wonder what the issue is though. Probably one of my work's old workbooks been cranky.

Thanks