VBA Macro used in the Microsoft Office Outlook Application

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

Search for Outlook Macros

Recent Macros

VBA Macro used in the Microsoft Office Word Application

Word InputBox Call Macros | VBA Macro #27

More Macros More Buttons.  If you create enough macros you will begin to question if a button needs to be created for each one.  It is overwhelming when there are too many custom macro buttons to select from. This also makes navigating to run a specific macro difficult. To address this issue, we created the macro Word InputBox Call Macros! This Word macro displays an InputBox with a list of macros that can be called.  To call a specific macro just enter in the leading number and click ok. The concept of this macro is simple and helps you stay organized storing all macros within one button.

VBA Macro used in the Microsoft Office Excel Application

Excel Update Multiple Workbooks from One | VBA Macro #26

This Excel macro is the inverse of Copy Multiple Workbooks into One where separate Workbooks are being combined into one MASTER Workbook.  The Update Multiple Workbooks from One macro instead takes the current information from the MASTER Workbook and updates separate Workbooks. If you desire one source of information that can be easily distributed across multiple parties this macro is for you!

VBA Macro used in the Microsoft Office Excel Application

Excel Combine Macros #16 #18 #23 | VBA Macro #24

This macro is the combination of 3 Excel macros: Create Worksheet per Filter Value | VBA Macro #16, Save Worksheets as Workbooks | VBA Macro #18, and Create Emails with Workbooks Attached | VBA Macro #23. These macros used together automates an entire process! The time saved using this macro allows you to focus on how you can bring more value to your customers. Take a look at the Value Stream Map we discussed in the Macro Monday video.

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 Excel, Outlook, 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

Looking for more?

Subscribe as an Insider to receive additional rights.

Contact Us

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

Copyright © 2019 Leverage & Lean – Uptown Style WordPress theme by GoDaddy