Monday, June 3, 2013

Send emails through Outlook using Excel

Here is the VBA code to send emails from Outlook:

Sub SendEmails()
Dim OlApp As Object
Dim OlMail As Object

Set OlApp = CreateObject("Outlook.Application")
Set OlMail = OlApp.CreateItem(olMailItem)

With OlMail
    .Display
    .To = "aaa@gmail.com"
    .CC = "bbb@gmail.com"
    .Subject = "Test Email"
    .Attachments.Add "C:\Test.xlsx"
    .Body = "Test email"
    .Save
    .Close olPromtForSave
    .Send
End With

End Sub

1 comment:

  1. You might have come across with cases where you wanted to paste range of data from Excel into the body of the email. Please refer to the useful link, use the code "Function RangetoHTML(rng As Range)":

    http://www.rondebruin.nl/win/s1/outlook/bmail1.htm

    ReplyDelete