Skip to content
Primary Menu
  • Officetricks.Com
  • Blog
  • App Store
    • International Users
    • Indian Users
  • Subscribe
  • About Us
  • Excel
  • Social Media

VBA Macro – Choose Outlook Email Account – To Send Mass Mail

January 30, 2023
Kumarapush

Choose From Multiple Outlook Email Accounts

[ Table of Contents ]
I. Choose From Multiple Outlook Email Accounts
II. Get All Email Accounts Configured in Outlook
III. Send Mail Using Outlook Email Accounts

Marketing people send tons of emails daily, to their customer base.

If a customer is not interested in the offer, there are chances that the marketing email could go to spam folder.

How to overcome this issue?

Marketing people use a different email account to send same offer to same set of email distribution list. In this case, the automation explained in this article will be useful.

This code selects one of the multiple Outlook email accounts configured in your system. To know how to automate sending emails from Outlook or Excel, refer this topic.

Get All Email Accounts Configured in Outlook

The loop in this code reads all the accounts configured in the MS Outlook email client. If you are using this code from within Excel VBA, then add this reference before executing the code.

Note: Go to Menu from VBA editor -> Tools -> Reference -> Microsoft Outlook Object Library.
Also, ensure that Outlook is properly for atleast one email account in your computer to use this code.

Sub List_Outlook_Email_Accounts()
    'Declare Outlook Object - Add reference to Microsoft Outlook Object Library
    Dim OutApp As Outlook.Application
    Dim oAccountIdx As Long

    'Create Outlook Object - Ensure Outlook is properly configured in your machine
    Set OutApp = CreateObject("Outlook.Application")

    'Loop through each Outlook Email Account
    For oAccountIdx = 1 To OutApp.Session.Accounts.Count
        MsgBox OutApp.Session.Accounts.Item(oAccountIdx) & " : This is account number " & oAccountIdx
    Next oAccountIdx
    
    'Process Completed
End Sub

If this reference is not added, then the Outlook Objects with the VBA code has to be created as late binding objects.

Now, we know how to reference difference email accounts with in Outlook. Now, lets see how to use any of them while sending any email.

Send Mail Using Outlook Email Accounts

You can choose the Email account within code wither with its index number as we saw in previous loop. Or use any of the other properties.

Sub Send_Emails_Using_Account()
    'Declare Outlook Object - Add reference to Microsoft Outlook Object Library
    Dim OutApp As Outlook.Application
    Dim oOutlookEmail As Outlook.MailItem
    Dim objSendUsingAcct As Outlook.Account
    Dim strAcctName As String
    Dim oAccountIdx As Long

    'Create Outlook Object
    Set OutApp = CreateObject("Outlook.Application")
    Set oOutlookEmail = OutApp.CreateItem(0)

    'Get Acct
    strAcctName = "officetricks123@gmail.com"
    For oAccountIdx = 1 To Application.Session.Accounts.Count
        If VBA.InStr(1, Application.Session.Accounts.item(oAccountIdx).UserName, strAcctName, vbTextCompare) Then
            Set objSendUsingAcct = Application.Session.Accounts.item(idxAcct)
            Exit For
        End If
    Next
    
    If objSendUsingAcct Is Nothing Then
        MsgBox "Account Not Found: " & strAcctName
    Else
        'Send Email Using Excel VBA Macro Code'
        With oOutlookEmail
            .To = "recepientId@gmail.com"
            .CC = ""
            .BCC = ""
            .Subject = "Happy New Year"
            .Body = ToMSg
            .SendUsingAccount = objSendUsingAcct
            .Display 'or just put .Send to directly send the mail instead of display
        End With
    End If
    
    Set OutlookMail = Nothing
    Set OutApp = Nothing
End Sub

This is how we can have just one Outlook, Configure multiple any number of email accounts & send our clients from the account of our choice.

We don’t have to switch through each account every time manually. This happens when you have multiple email accounts or you share the same machine with multiple persons.

In either case, here is the code that will enable you to opt for any email account from within VBA.

Tagged in : automate enail bulk email Choose Email Account Excel Send email mass email multiple Email accounts outlook vba send bulk email send mail sendusing

Related Articles

Compare Two Columns Excel – Highlight Match – Bulk Data Duplicates

How to Convert Excel to Access Database?

Excel VBA html Table import – Export Web Table to Worksheet

Post navigation

Previous Previous post: Determine Operating System – Excel VBA Macro – Find OS Details
Next Next post: Copy WhatsApp Status Photo & Video
Excel Excel VBA Macro OutLook Outlook Macro
Excel Tricks
  • Intersect method (Excel)
  • LET( ) Function in Excel
  • Excel Compare Two Columns for Duplicates – Highlight Differences
  • Excel VBA Dictionary Datatype – Create & Add Keys, Items
  • Excel VBA – Convert Column Number to English Alphabet Letter
  • How to run VBA Macro Daily without opening Excel file autiomtically?
  • Convert CSV to Vcard File – Download Converter App
  • Python Program To Check Palindrome
  • Not a Secret Anymore – What is my IP Address Location? Bulk GeoIP Lookup
  • Open Text File – Read Write File Operations – VBA, Python, VBS, C, C++, DOS
  • Run Macro When Cell Value Changes or Range VBA
  • Making SORT More Simple and Faster in Excel with Advanced Options
  • Convert Excel To PDF – VBA Code Print Selected Area
  • [VBA] Read Values in Data Validation Drop Down List
  • Excel VBA Hyperlink Follow – URL within Macro
Excel VBA Macro Tricks
  • How to Zip File or Folder using VBA Code – Excel Macro?
  • Build Excel Organization Chart – Hierarchy Tree – From Data
  • Excel VBA Timer Event – Run Macro at Specific Time – Automatic Schedule
  • Create Random Numbers in Excel and Google SpreadSheets
  • Microsoft Office – Communicator API – Verify Availability Status
OutLook Tricks
  • Save Outlook Mail Attachment to Local Folder
  • Open VCF File Online – Free VCF Viewers & Editors
  • This Tiny VBA Can Send Email to All contacts in Your Outlook
  • Outlook Archive Email – Move Email To PST – VBA Macro
  • Excel VBA Send Email at Specific Time – Outlook Delayed Delivery
  • Bulk Excel VBA Send Email with Attachments – 2 Multiple recipients
  • GB Whatsapp Features – Easy Download Steps
  • Excel VBA For each cell in Range – Direct method
  • Excel VBA Send Email at Specific Time – Outlook Delayed Delivery
  • How to Save Web Page as PDF File – No Plugins Required
  • Excel vba send email with attachments using Outlook App Mass Bulk email
    Bulk Excel VBA Send Email with Attachments – 2 Multiple recipients
    Get Excel vba send email with attachment code that uses Outlook app already installed. Send bulk emails to multiple recipients with different email.
  • GB Whatsapp Features Smartphone Messaging App Download page
    GB Whatsapp Features – Easy Download Steps
    Learn GB WhatsApp features compared to the original WhatsApp app. It offers enhanced security, privacy settings, customizations & more
  • Excel VBA Loop for each cell in Range of Worksheet
    Excel VBA For each cell in Range – Direct method
    Learn how to loop in Excel VBA for each cell in range of a worksheet. Also get its row, column numbers and values with the loop.
  • Officetricks.Com
  • Blog
  • App Store
    • International Users
    • Indian Users
  • Subscribe
  • About Us
  • Excel
  • Social Media
Copyright All rights reserved