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 Outlook Application

Outlook Greeting and Goodbye Contacts | VBA Macro #35

The Greeting and Goodbye Contact macro automates the entry of a Greeting “Good Morning” or “Hello” followed by the First Name of the recipient you are emailing. To identify the First Name this macro uses the recipient’s email address to loop through all the existing contact records for a matching email address. If a match is found the contact’s First Name field value is used in the beginning of the email. The appropriate Greeting and Goodbye is determined by the current time and the day of the week. The Greeting and Goodbye Contacts macro helps you deliver better customer service and create better connections with your clients!

VBA Macro used in the Microsoft Office Excel Application

Excel Custom Questionnaire to File | VBA Macro #34

This is an Excel macro that generates a custom questionnaire to complete.  The Role field is used to determine what questions display for specific users.  Once a user selects their Role, they can click Generate to see what questions they need to complete to finish the questionnaire.  After a user has completed all the required questions, they can click Finish to create a separate Excel Workbook with all the populated answers.   You can customize where this new file is saved making it easy to know when someone has completed a questionnaire and is awaiting review. There is also the option to send this separate Excel Workbook in an Outlook email with a couple updates to the VBA code. There is always a better way with VBA and this Excel macro helps standardize the collection of answers to specific questions. This can help lead to a more formal review process and eliminate mistakes.

VBA Macro used in the Microsoft Office Outlook Application

Outlook Hello Contacts | VBA Macro #33

Starting an email with a Hello can look more personable with some VBA code! The Hello Contacts Outlook macro automates the entry of the text Hello followed by the First Name of the recipient you are emailing. This Outlook macro uses the recipient’s email address to loop through all the existing contact records for a matching email address. If a match is found the contact’s First Name field value is used in the beginning of the email. This macro can be fired from a custom button or trigger automatically when replying to an email.

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