Follow by Email

Tuesday, March 18, 2014

Basic examples for Outlook VBA

This post contains few basic examples for VBA in Microsoft Outlook. To get developer tab visible, File -> Option -> Customize Ribbon -> Developer.

Let see a simple example to send an email. Below is the basic code which will generate and shoot the email. In visual Basic Editor, use ThisOutlookSession or any other user modules.

Private Sub SendEmail()
Dim olObj, mlObj
Set olObj = CreateObject("Outlook.Application") 'declaring object
Set mlObj = olObj.CreateItem(0) 'declaring an email item
With mlObj
.To = "me@mydomain.com" 'Give your email
.Subject = "Testmail" ' Give the subject
.Body = "Testmail" ' Give the Body
.Send 'command to send the email
End With
Set olObj = Nothing 'Clear the memory
Set mlObj = Nothing
End Sub