How to send bulk emails from outlook using excel 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.

VBA Code to Draft Outlook Emails

Write a Code to Send Emails from Outlook using Excel VBA 

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
Draft Outlook Email through Excel

How do we Reference Outlook from Excel?

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:

  •  From the Menu Bar, click on Tools > References…
send outlook emails
  • Select Microsoft Outlook XX.X Object Library and click on ‘OK’ button
send outlook emails

Steps to use this VBA Code

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…’

Draft Outlook Email through Excel

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

Draft Outlook Email through Excel

9. Done

 

Download Practice File for Free

To help you practice this code, we have made this code available through practice file. Click on the below link to download the practice file.

Recommended Articles

Similar Posts

25 Comments

  1. 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!

    1. 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

  2. Marty Christopherson says:

    Thank you for publishing this example. Everything works great in my environment, with one exception. When I send the draft e-mail, the e-mail is bounced because my company domain was attached to the e-mail address pulled from the spreadsheet. For example, from my spreadsheet the email address [email protected] is being sent to [email protected]@mycompany.com. If I manually type the email address or even copy/paste from Excel into Outlook, it displays exactly the same in Outlook as the one populated from Excel but those are sent correctly. Any idea why? Thanks again!

    1. Hi Marty,

      Please accept our apologies for delayed response.

      The issue explained by you seems to be caused due to mailto tag available in To (Column A) and Cc (Column B) in the sheet. Please ensure that email id mentioned in the Excel sheet is plain text and no hyperlink or mailto tag is attached to it.

      Regards,
      Your Excel Mate

      1. Hi,

        Thanks for the code.

        I need to attach multiple files based on partial filename within the same folder.

        Can you please kindly how can I achieve that using above draft email outlook code.

        Thanks in advance.

        1. Hi Shiva,

          You can try below code where new variable named strBaseFolderPath has been added to define base folder path where attachments are saved:

          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
              Dim strBaseFolderPath As String
              
              'Base folder path where attachments are saved
              strBaseFolderPath = "D:\Work\Files\"
              
              'Set objects
              Set objOutlook = Outlook.Application
              'Read details from Excel sheet and draft emails
              For lCounter = 6 To 8
                  '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 strBaseFolderPath & (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

          Note that this code does not attach multiple files in one email instead only one attachment can be added per email.

          You can also have a look at https://products.excelsirji.com/downloads/outlook-bulk-email-tool/. Though it also does not support multiple attachments per email but we can customize it for you.

          Regards
          ExcelSirJi Team

  3. It runs and says “done” but there is no draft email popping up or in the outlook email box. I have Microsoft Outlook 16.0 Object Library added in reference.

    1. Could you please check “Draft” folder in your outlook. It should show there. Thanks

  4. Hi Sir,

    Thnks a lot for the above. Works well.

    However, lets say the word “test” in email body should be Bold, i have it as bold in the excel sheet but when the mails are drafted it does not appear as bold. Is there a way to solve this?

    Best,

    1. Hi Domah,

      It may not be simple but let me suggest you have way out.

      First replace the code objMail.Body = Sheet1.Range("D" & lCounter).Value with objMail.HTMLBody = Sheet1.Range("D" & lCounter).Value

      Then write email body in Excel in HTML format, something like below:

      Hi,
      This is a <b>test</b> email 1.

      Thanks

      Note that there is a bold tag added for test word.

      Then run the code, it should work.

      Thanks & Regards,
      ExcelSirJi Team

  5. Hello,

    I copied this code tried to Run but I didnt find this Excel sheet to fill details For To,cc etc. Can u plz guide on this.
    If possible please share Macro to if not possible then pl guide here how can I do this?

  6. Rahul Kumar Soni says:

    Hi I tried using the above VBA code to automatically create draft mail, but all the time only blank mails are formed please help

    1. There could be 2 reasons for this:

    2. Either you are not referring to the right sheet i.e. Sheet1 is hardcoded in the given code, so you need to refer to the sheet from where you are sending emails. To know the sheet name, press ALT+F8 and then look the sheet name on the left side under project explorer and replace the sheet name.
    3. Or just check the Mail attributes referring to the right column i.e. objMail.Body in the given code is referring to Column D, so please verify your email body content is entered in the same column or change the column name
    4. Hope this would solve your problem.

      1. Rahul Soni says:

        HI,

        I tried what you have written, but event though, all mail attributes are right, then also my emails, to , cc , subject, body,, still everything is empty

        please help

        1. I will share a video this week on the same on my YouTube channel. Hope that may help.

  7. Hi! Thank you for the code. May I have an additional code to the existing that includes a table on the body? Thank you.

Leave a Reply

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