Create or Compose Outlook Email using Visual Basic for Applications

MailItem

Object exposed by application object exposes various properties refers to a New Email like To, CC, BCC, Subject, body etc. In this article we will put code to create a new email and populate said properties from Excel to send email. This could be very useful when you wish to send bulk emails from a CSV or excel file.

Code example

Sub createEmails()
    'Outlook application object declaration
    Dim oApp As Outlook.Application
    
    'bind current outlook instance
    Set oApp = GetObject("", "Outlook.Application")
    
    
    'Declare Mail object
    Dim oMailItem As MailItem
    
    'Create new mail item
    Set oMailItem = oApp.CreateItem(olMailItem)
    
    'Assign proerties
    oMailItem.To = Range("B2")
    oMailItem.Subject = Range("B3")
    oMailItem.Body = Range("B4")
    
    'Display mail
    oMailItem.Display
    
    'Send
    oMailItem.Send
    
    'Close outlook
    oApp.Quit
    'CleanUp
    If Not oMailItem Is Nothing Then
        Set oMailItem = Nothing
    End If
    
    If Not oApp Is Nothing Then
        Set oApp = Nothing
    End If
End Sub

Input

Output

Next >> Extract or Export Emails from Outlook to Excel with code example

Leave a Reply

Your email address will not be published. Required fields are marked *