Email from Excel

< Back to home

< Back to development tips

Sending emails from excel is very easy and powerful.  The example below provides basic VBA code to create an email, ready to be sent.

For this code to work you must first enable the Microsoft outlook object library.  See bottom of this page for a guide to do this.

Public Sub SetupEmail()
     Dim emailApplication As Object
     Set emailApplication = CreateObject("Outlook.Application")
     Dim emailitem As Object ' Outlook.MailItem
     Set emailitem = emailApplication.CreateItem(0)
     emailitem.To = ""
     emailitem.Subject = "Email subject"
     emailitem.Body = "Email body"
     emailitem.Attachments.Add ("C:\blank.docx")

    ' emailitem.send  - if you want to send email without reviewing

     Set emailitem = Nothing
     Set emailApplication = Nothing
End Sub



Procedure to active Microsoft Outlook Object Library

Step 1:  In VBA click  > Tools > References

Step 2: 

Check Microsoft Outlook Object Library > Click OK


< Back to home

< Back to development tips