Outlook Create Multiple Emails | VBA Macro #25

Share on facebook
Share on twitter
Share on linkedin
You just completed a task on your computer and now you need to email some impacted parties letting them know the task is complete.  Let’s say for example you have to email the client, the billing department, and your supervisor.  You could send one email including all these recipients but this is a problem if you are sending sensitive information specific to everyone involved.  Even if there isn’t sensitive information someone can use Reply All creating an email thread with everyone included.  Example the billing department has a follow up question for you but the client is pulled into the email.  This can be frustrating for the client if there is an internal question being asked that isn’t relevant to them. There has to be a better way…of course there is with VBA! This Outlook macro will create multiple emails based on the number that you indicate in an InputBox.  By Default, all the emails created will be blank but this macro is designed to reference the email counter allowing you to create unique emails. Think of this Create Multiple Emails macro as a code template that allows you generate multiple emails pertaining to different topics. Using the email counter, you can indicate the email recipients, email subject, and email body.  So, when this macro hits that number the email is populated with the values you indicated in these fields.  Using the example above the first email can be dedicated to the client, the second email for the billing department, and the third email for your supervisor.  You can even avoid the InputBox and set a predetermined amount of emails in this Outlook macro.

See it in Action!

Watch this video to see this macro in action.

The Code

Here is the code for this macro. Make sure the following References are setup before running it: Visual Basic For Applications, Microsoft Outlook 16.0 Object Library
'Leverage & Lean "Less Clicks, More Results"
Sub CreateMultipleEmails()
' Means variable is in use
Dim Answer As Variant '
Dim Body As String '
Dim CCRecipients As String '
Dim EmailCount As Integer '
Dim NewEmail As Object '
Dim Outlook As Object '
Dim Recipients As String '
Dim Subject As String '

On Error GoTo LeverageLean

Answer = InputBox("How many emails do you want to create?", "Outlook Create Multiple Emails") 'Enter the number of emails you want to create
'EmailCount = 10 'Enter a set number of emails to avoid populating the InputBox

'Ensure that the Answer entred is a valid number. If not Exit Sub. ***Remove to EmailCounter if defaulting EmailCount above
If Not IsNumeric(Answer) Then
Exit Sub
ElseIf Answer = "" Then
Exit Sub
Else
EmailCount = CInt(Answer)
End If

EmailCounter = 1

Do Until EmailCounter > EmailCount
If EmailCounter = "1" Then
Recipients = ""
CCRecipients = ""
Subject = ""
Body = ""
ElseIf EmailCounter = "2" Then
Recipients = ""
CCRecipients = ""
Subject = ""
Body = ""
ElseIf EmailCounter = "3" Then
Recipients = ""
CCRecipients = ""
Subject = ""
Body = ""
ElseIf EmailCounter = "4" Then
Recipients = ""
CCRecipients = ""
Subject = ""
Body = ""
ElseIf EmailCounter = "5" Then
Recipients = ""
CCRecipients = ""
Subject = ""
Body = ""
Else
Recipients = ""
CCRecipients = ""
Subject = ""
Body = ""
End If

Set Outlook = CreateObject("Outlook.Application")
Set NewEmail = Outlook.CreateItem(0)

With NewEmail
.To = Recipients 'Set Recipients indicated by EmailCounter above
.CC = CCRecipients 'Set CCRecipients indicated by EmailCounter above
.Subject = Subject 'Set Subject indicated by EmailCounter above
.HTMLBody = "<HTML><BODY><span style=""font-family : Calibri;font-size : 11pt"">" & Body & "</p></span></BODY></HTML>" ''Set Body indicated by EmailCounter above
.Display
End With

EmailCounter = EmailCounter + 1

Loop

Exit Sub

LeverageLean:
MsgBox (Err.Number & " - " & Err.Description & vbNewLine & vbNewLine & "Don't hesitate to email me: brentschneider@leveragelean.com")
   
End Sub
'Stay Awesome

Macro Monday

Here is the Macro Monday video this macro was featured in. Watch this video to learn how to get the most out of this macro and start using it today!

Customization

These lines of code can be customized to personalize this macro.
15. Answer = InputBox(“How many emails do you want to create?”, “Outlook Create Multiple Emails”) This code line displays the InputBox to enter how many emails to create. Look to code line 16 to bypass the InputBox
16. ‘EmailCount = 10 ‘Enter a set number of emails to avoid populating the InputBox You can activate this code line and set a default amount of emails to create. (Remove code line 15)
18 through 25 ‘Remove to EmailCounter if defaulting EmailCount If setting a default EmailCount in code line 16 you need to remove code lines 18 through 25
30 through 54 If EmailCounter = “1” Then Referencing the EmailCounter you can set the Recipients, CCRecipients, Subject, Body in the emails being created
55 through 60 Else These code lines ensure that an emails are blanks if the EmailCounter is greater than the last populated email above
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments

First time using VBA?

The Developer Tab is an additional section of the ribbon when activated allows you access to Visual Basic in Applications like Access, Excel, Outlook, PowerPoint, Word.
Setup Now
Once the Developer Tab is available you will have the capability to update your security to allow Macros to run in the current application.
Setup Now
A sub of code is a collection of objects and variables. For the code to successfully run a library of references needs to be set.
Setup Now
Subscribe as an Insider to receive additional rights.
If you like our content and want to show your support tip us here!

Contact Us

Looking to improve your computer processes?
Leverage & Lean is here to help!

Leverage & Lean

Is focused on improving computer processes by Leveraging programming and applying Lean principles. It is our goal to make you more efficient and effective on your computer producing “Less Clicks and More Results!”