Choose From Multiple 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.List all Outlook Email Accounts Using Excel VBAVisual Basic123456789101112131415Sub List_Outlook_Email_Accounts()'Declare Outlook Object - Add reference to Microsoft Outlook Object LibraryDim OutApp As Outlook.ApplicationDim oAccountIdx As Long'Create Outlook Object - Ensure Outlook is properly configured in your machineSet OutApp = CreateObject("Outlook.Application")'Loop through each Outlook Email AccountFor oAccountIdx = 1 To OutApp.Session.Accounts.CountMsgBox OutApp.Session.Accounts.Item(oAccountIdx) & " : This is account number " & oAccountIdxNext oAccountIdx'Process CompletedEnd 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.Choose Outlook Email Account Using Excel VBAVisual Basic123456789101112131415161718192021222324Sub Send_Emails_Using_Account()'Declare Outlook Object - Add reference to Microsoft Outlook Object LibraryDim OutApp As Outlook.ApplicationDim oOutlookEmail As Outlook.MailItemDim oAccountIdx As Long'Create Outlook ObjectSet OutApp = CreateObject("Outlook.Application")Set oOutlookEmail = OutApp.CreateItem(0)'Send Mass Email Using Excel VBA Macro CodeWith oOutlookEmail.To = "email@example.com".CC = "".BCC = "".Subject = "Happy New Year".Body = ToMSg.SendUsingAccount = OutApp.Session.Accounts.Item(1).Display 'or just put .Send to directly send the mail instead of displayEnd WithSet OutlookMail = NothingSet OutApp = NothingEnd 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.
Previous Post: Determine Operating System – Excel VBA Macro – Find OS Details
Next Post: 2018 – Hack Whatsapp Friends – Status Photos
VBA Macro – Choose Outlook Email Account – To Send Mass Mail