Tuesday, 21 May 2013

Excel Macro to Send Email from Outlook with attachment

Below Excel Macro Example will send the email from outlook with attachment. You can attach any file like ,xls, .pdf etc.

You can also send an email based on cell value. For example - if cell value is Yes, Then it will send an email.
The email is sent automatically provided that your email client outlook is configured correctly.

Please note that this macro cannot  be used to send an email from lotus notes.

You can send an email to multiple addresses/recipients by just editing the TO property of mail item object in below example.

Code / Syntax to send an email from outlook through excel macro.

Set Outlook = CreateObject("Outlook.Application") 
Set Message = Outlook.CreateItem(0) 
With Message 
       .Subject = "Any Subject "
       .HTMLBody = "Any TextBody "
       .Recipients.Add ("abc@gmail.com") 
 End With 
 Set myAttachments = Message.Attachments 
 myAttachments.Add "C:\my.doc",1, 1, "my" 
 Message.Display 
  Message.Send 


Above program will send an email to abc@gmail.com with my.doc attached to it.

Please note that to send the workbook as attachment, it can be done very easily with below line of code

ActiveWorkbook.SendMail "sagar.salunke@sunagrd.com"

Please note that your outlook client should be working fine.





No comments:

Post a Comment

Popular Posts

Search This Blog