Business Analytics
Data Analyst
Programming for Data Science
Predictive Analytics for Business
Are you a data enthusiast? Join us for a ride on your data and automate your stuffs

VBA Code to Draft Outlook Emails

Outlook Tricks VBA

Have you ever felt the need of an Excel based VBA tool or code which can help you to draft Outlook emails in bulk by reading recipients and other details from Excel? Here is very simple solution to your problem, you can use below VBA code to draft emails in Outlook draft folder.

Excel Tricks

Public Sub DraftOutlookEmails()
    'Microsoft Outlook XX.X Object Library is required to run this code
    'Variable declaration
    Dim objOutlook As Outlook.Application
    Dim objMail As Outlook.MailItem
    Dim lCounter As Long
    'Set objects
    Set objOutlook = Outlook.Application
    'Read details from Excel sheet and draft emails
    For lCounter = 6 To 8    'You can change the counter as per requirement
        'Create a new email item
        Set objMail = objOutlook.CreateItem(olMailItem)
        'To
        objMail.To = Sheet1.Range("A" & lCounter).Value
        'Cc
        objMail.CC = Sheet1.Range("B" & lCounter).Value
        'Subject
        objMail.Subject = Sheet1.Range("C" & lCounter).Value
        'Email Body
        objMail.Body = Sheet1.Range("D" & lCounter).Value
        'Add Attachment
        objMail.Attachments.Add (Sheet1.Range("E" & lCounter).Value)
        'Draft email
        objMail.Close (olSave)
        'Close the object
        Set objMail = Nothing
    Next
    'Show confirmation message to user
    MsgBox "Done", vbInformation
End Sub

Excel Tricks

It is worth to mention that you must have MS Outlook installed in your system to use this code and you also need to add Office reference (Microsoft Outlook XX.X Object Library) in Excel VBA from Menu Bar (Tools>References…). Below are the steps to add Office reference in Excel VBA:

1. From the Menu Bar, click on Tools > References…

Excel Tricks

2. Select ‘Microsoft Outlook XX.X Object Library’ and click on ‘OK’ button

Excel Tricks

To use this code in your Excel file, follow below steps:

1. Open an Excel file
2. Press Alt+F11
3. Insert a Module (Insert>Module) from menu bar
4. Paste the code in the module
5. Now add a shape in Excel sheet
6. Give a name to the shape like ‘Draft Outlook Emails’
7. Right click on the shape and select ‘Assign Macro…’

Excel Tricks

8. Select ‘DraftOutlookEmails’ from the list and click on ‘Ok’ button

Excel Tricks

9. Done 

Outlook Email Management Tool
Comments
  • Sam Harper says:

    How can I reference a table I want to add in email body? Lets say for example I want a table (with matched formatting) in between this is a test email 1 and thanks?

    Also how would you go about including a signature?

    Thanks!

    • excelsirji says:

      Thanks Sam for highlighting your challenge. This seems a customized requirement. We are currently working on VBA Utilities which will be available under Tools and Templates Section soon. Hope that will help your needs.

      If you are looking to hire a VBA expert to complete your project, you may submit your project details at https://excelsirji.com/hire-us/ and we will get back to you in 48 hours with details.

      Happy Reading 🙂

      Your Excel mate

Leave a Reply

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