Pages

Friday, July 2, 2010

Macro to send Email using Outlook from Excel

If you want to send an email from Excel using Outlook . Try this macro




Sub send_email_via_outlook()

' Tools - Refrence - Microsoft Outlook


Dim olApp As Outlook.Application
Dim olMail As MailItem


Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)

With olMail
    .To = "koul.ashish@gmail.com"
    .Subject = "Hello"
    '  vbNewLine  is used to insert a row
    .Body = "Dear Ashish" & vbNewLine & "Please find the attachment" & vbNewLine & vbNewLine & vbNewLine & "Regards" & vbNewLine & "Ashish Koul"
    .Attachments.Add "C:\Documents and Settings\user\Desktop\Excel Tips & Tricks\01.jpg"
    .Display ' or use .send
End With


Set olMail = Nothing
Set olApp = Nothing

End Sub


Download Working File



Steps to Use


  • Copy the below code
  • Press Alt+F11 to open VBA editor
  • Paste it in any public module or module 1
  • Run the Macro


No comments:

Post a Comment