Hi,
I've successfully been using the VBA code (see attached sample file) to attach an excel file to an Outlook email. Using 2010 Excel 2010 and Outlook.
In the body of the email, I wish to insert a small word doc or a .jpg file (whichever is easier) instead of the contents in cell B5.
How do I update the VBA code?
I've search the internet, but the code found is beyond my skill level.
All help is greatly appreciated. Thanks and have a great day.
Hi Carolyn
Try changing this line of your code from xlsx to jpg/docx etc
If InStr(1, AttachFile, "docx", vbTextCompare) Then
In cell B4 change the file name.
You can also do away with the If...ENDIF and only use .Attachments.Add AttachFile
In this way, it will not check on the type of file but will send whatever you entered in cell B4.
NOTE
I think you should not put your actual e-mail address on the test file.
Otherwise you will be flooded with e-mails when we test your codes
Hope this helps.
Sunny
Hi Sunny,
Apologies for not getting back to you sooner!
Your advise was helpful. I was able to figure out how to add the .jpg to the body of the email along with attaching an excel file.
Attached is the file with the VBA and the Mail worksheet set-up. May be of help to others.
I have one last question, you mentioned "You can also do away with the If...ENDIF and only use .Attachments.Add AttachFile". My code still has the filter for "xls". Would you be so kind as to let me know what the code should be to remove the filter, lines 25:29?
Thanks again!
Carolyn
Hi Carolyn
I was referring to this (lines 30-32):
If InStr(1, AttachFile, "xls", vbTextCompare) Then
.Attachments.Add AttachFile
End If
Here you are only attaching files with the xls extensions and will ignore others.
I was suggesting you remove the lines in red.
BTW there is no attachment in your post #3
Cheers
Sunny
Hi Sunny,
Your answer did the trick!
Let's try that again... attaching the file with the VBA code and "dummy" email address.
Thanks for your patience and help on this. Have a great weekend.
Carolyn
Hi Carolyn
Thank you for your feedback.
Glad that we could help.
Cheers
Sunny