• Outlook User
  • Exchange Admin
  • Office 365
  • Outlook Developer
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
    • Common Problems
    • Outlook BCM
    • Utilities & Addins

Create a new Outlook message using VBA

Slipstick Systems

› Developer › Create a new Outlook message using VBA

Last reviewed on June 29, 2015     127 Comments

You can use a VBA macro to create a new message and preset any of the fields, including To/CC/BCC, the subject, expiration date, flags, voting options and more.

To use, use Alt+F11 to open the VBA editor and paste the following code into ThisOutlookSession. Remove the fields you don't want to set and edit the values in the fields you want to set automatically.

Add the macro to a toolbar or ribbon button or to the QAT.

Public Sub CreateNewMessage()
Dim objMsg As MailItem

Set objMsg = Application.CreateItem(olMailItem)

 With objMsg
  .To = "Alias@domain.com"
  .CC= "Alias2@domain.com"
  .BCC = "Alias3@domain.com"
  .Subject = "This is the subject"
  .Categories = "Test"
  .VotingOptions = "Yes;No;Maybe;"
  .BodyFormat = olFormatPlain ' send plain text message
  .Importance = olImportanceHigh
  .Sensitivity = olConfidential
  .Attachments.Add ("path-to-file.docx")

' Calculate a date using DateAdd or enter an explicit date
  .ExpiryTime = DateAdd("m", 6, Now) '6 months from now
  .DeferredDeliveryTime = #8/1/2012 6:00:00 PM#
  
  .Display
End With

Set objMsg = Nothing
End Sub

Send a new message to From address of selected messages

You can easily tweak the macro above to loop through a selection of messages and send a new message to the senders.

To use, select one or more messages then run the macro. As written, it opens the messages so you can review them and send yourself. You can change .display to .Send if you want to send them automatically. (Use .display when testing.)

Public Sub CreateNewMessage()
Dim objMsg As MailItem
Dim Selection As Selection
Dim obj As Object

Set Selection = ActiveExplorer.Selection

For Each obj In Selection

Set objMsg = Application.CreateItem(olMailItem)

 With objMsg
  .To = obj.SenderEmailAddress
  .Subject = "This is the subject"
  .Categories = "Test"
  .Body = "My notes" & vbcrlf & vbcrlf & obj.Body 
  .Display
' use .Send to send it automatically 

End With
Set objMsg = Nothing

Next

End Sub

Create a new contact with some fields filled in

You can use the same method with other Outlook items. This example creates a new contact with a country and city and part of phone number.

Use TaskItem and olTaskItem for Tasks, AppointmentItem and olAppointmentItem for appointments. You'll need to replace the fields with the correct properties for the item type. You can get the property names from VBA Help or at MSDN.

Public Sub CreateNewContact()
Dim objContact As ContactItem

Set objContact = Application.CreateItem(olContactItem)

 With objContact 
  .BusinessAddressCity = "Halifax"
  .BusinessAddressCountry = "Canada"
  .Business2TelephoneNumber = "902123" 'the area code and local prefix
  .Display
End With

Set objContact = Nothing
End Sub

Create a new Appointment

This macro creates a new appointment with the Location field filled in. Other fields can be added to it and if you need an meeting, click Invite attendees on the ribbon.


Sub CreateApptLocation()

Dim olAppt As AppointmentItem
Set olAppt = Application.CreateItem(olAppointmentItem)

With olAppt
   .Subject = "My Subject"
   .Location = "My Favorite place"
   .Categories = "Business"
   .Display
End With
End Sub

Create a new Outlook message using VBA was last modified: June 29th, 2015 by Diane Poremsky
  • Twitter
  • Facebook
  • LinkedIn
  • Reddit
  • Print

Related Posts:

  • Do you send a lot of messages to one person or group and want to make
    How to create preaddressed messages
  • New message to selected contacts using the BCC field
  • Use this macro to send an attachment to email addresses in the To line
    VBA: No attachments to CC'd recipients
  • Create a deferred Birthday message for an Outlook Contact

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
127 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

R.P. (@guest_219151)
February 5, 2022 11:23 am
#219151

How to use a variable to assign like .to = %var%? Is this possible?

0
0
Reply
Jimmy (@guest_215243)
May 21, 2020 1:05 am
#215243

Hello Diane
Thanks for this great post. Wondering if you can help - I receive emails with the subject and attachments as i want them (from our accounting software). I am wondering if i could have a macro set to a button that
a) opens a forward draft (so i can add the clients name)
b) adds certain text to the body of the draft (generally the same on each one)

Even better would be to open a NEW email and copy across the attachments and subject of the email i get from the system so that i dont have to delete traces of initial email.

0
0
Reply
DivEff (@guest_213636)
July 21, 2019 2:52 am
#213636

Thank you very much for this article! It helped me to create new email object where I can copy extracted text from multiple emails into it.

0
0
Reply
Sahil Bhargava (@guest_213107)
April 17, 2019 1:50 am
#213107

Hi,
I want to modify my .To and .Cc based on the following conditions:
.To : Ops MANAGER
.Cc: Managers(under him)

Example:
I have the following columns with me:
Ops Manager 1 Manager 1
Ops Manager 1 Manager 2
Ops Manager 2 Manager 3
Ops Manager 2 Manager 4
Ops Manager 3 Manager 5

.To : Ops Manager 1
.Cc : Manager 1, Manager 2

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Sahil Bhargava
April 17, 2019 11:27 pm
#213111

For things like that, i recommend using multiple macros - ones with the addresses as strings that calls the main macro and passes the values.

Dim strTo As String
Dim strCC As String

Public Sub ToMgr1()
strTo = "manager1@domain.com"
strCC = "alias@domain.com;alias2@domain.com"
CreateNewMessage
End Sub

Public Sub ToMgr2()
strTo = "manager2@domain.com"
strCC = "alias3@domain.com;alias4@domain.com"
CreateNewMessage
End Sub

Private Sub CreateNewMessage()
Dim objMsg As MailItem

Set objMsg = Application.CreateItem(olMailItem)

 With objMsg
  .To = strTo
  .CC = strCC
  .Subject = "This is the subject"
  .Display
End With

Set objMsg = Nothing
End Sub

0
0
Reply
Anoop Kumar (@guest_214639)
Reply to  Sahil Bhargava
January 21, 2020 7:26 am
#214639

hi, didyou get the answer?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Anoop Kumar
January 21, 2020 8:38 am
#214642

To do something like this, where it is dynamic and the To changes? You would need to use multiple macros - the macro needs to add the addresses before opening.

Ops Manager 1 Manager 1
Ops Manager 1 Manager 2
Ops Manager 2 Manager 3
Ops Manager 2 Manager 4
Ops Manager 3 Manager 5

.To : Ops Manager 1
.Cc : Manager 1, Manager 2

You can use a "stub macro" that sets the values and then calls the main one -

Dim strTo as string
Dim strCC as string
Dim strBCC as string

Public sendToBob()
strTo = "op1@domain.com"
strCC = "mrg1@domain.com"
strBCC = "address@domain"
CreateNewMessage
End Sub

Public sendToMary()
strTo = "op2@domain.com"
strCC = "mrg2@domain.com"
strBCC = "address@domain"
CreateNewMessage
End Sub

Private Sub CreateNewMessage()
Dim objMsg As MailItem

Set objMsg = Application.CreateItem(olMailItem)

 With objMsg
  .To = strTo
  .CC= strCC
  .BCC = strBCC
  .Subject = "This is the subject"
(rest of macro snipped)

0
0
Reply
Gabor Roth (@guest_213005)
April 2, 2019 10:30 am
#213005

Hi,
I'd like to create e-mails automatically sent out using the following criteria:
If end of the month is Monday or Thursday.
Is it possible somehow?
Would be great if it also worked when Outlook is not opened.

thanks in advance,
Gabor

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Gabor Roth
April 2, 2019 5:02 pm
#213007

Sending with outlook closed would require powershell (and it would open outlook).

You're wanting to send if the 30th is a mon or thurs? (or 31 or 28/29) I would check to see if date + 1 = 1 then check if today was mon or thurs.
Something like DateSerial(Month(Date) + 1) = 1
then check the day name:
WeekdayName(Weekday(Now())) = "Monday" Or WeekdayName(Weekday(Now())) = "Thursday" Then

I have a macro that should point you in the right direction at
https://www.slipstick.com/developer/code-samples/delay-sending-messages-specific-times/

0
0
Reply
chucky (@guest_212956)
March 19, 2019 8:21 pm
#212956

Although I am not a newb at programming here is a funny story and warning too. If you try all this send mail code, do not test it with the email account Outlook is set too or you will spend a week and many hours sifting through the internet trying to figure out why the mail is being sent to the outbox and not actually sending the email, there is no help on that. I accidentally figured it out myself when I sent some mail not via code to the wrong address, namely my own. It went to the outbox, I was like WTF, all that time I spent trying to figure it out. It would have been nice if there was some documentation provided saying "hey, if you send mail to yourself it will go to the outbox". I hope you had fun laughing :)

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  chucky
April 2, 2019 5:07 pm
#213008

>> "hey, if you send mail to yourself it will go to the outbox".
If the code sends the message, it should send it and come back to the inbox :)

Some of the macro samples display the messages instead of actually sending them - this is so you can see what they look like without actually spamming someone (my sample addresses) or yourself.

0
0
Reply
Mark (@guest_212203)
November 2, 2018 6:09 pm
#212203

Hi, I'm learning how to write Microsoft outlook VBA code from scratch. Where should I able begein to write code? Thanks!

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Mark
November 3, 2018 12:49 am
#212205

Unlike the other office apps, Outlook doesn't have a macro recorder, so you need to write it yourself or work with macros you find online. You'll write / edit it in the VBA editor.

0
0
Reply
Andres Meluk (@guest_207115)
June 14, 2017 10:37 am
#207115

This would be to send a file to a sender after he/she sends or texts "send file 400".

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Andres Meluk
October 8, 2017 10:31 pm
#208903

sure. i don't have a sample for this specific scenario, but i have one that creates appointments that gives you an idea how to do it.
https://www.slipstick.com/developer/code-samples/create-appointment-email-automatically/

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 28 Issue 21

Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Subscribe to Exchange Messaging Outlook






Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • WeekMonthAll
  • How to Remove the Primary Account from Outlook
  • Adjusting Outlook's Zoom Setting in Email
  • Uninstall Updates in Office 'Click to Run'
  • Move an Outlook Personal Folders .pst File
  • Save Sent Items in Shared Mailbox Sent Items folder
  • Create rules that apply to an entire domain
  • View Shared Calendar Category Colors
  • How to Create a Pick-a-Meeting Request
  • Outlook's Left Navigation Bar
  • Use PowerShell to get a list of Distribution Group members
  • Create a rule to delete spam with no sender address
  • Open Outlook Folders using PowerShell or VBScript
  • Cannot add Recipients in To, CC, BCC fields on MacOS
  • Change Appointment Reminder Sounds
  • Messages appear duplicated in message list
  • Reset the New Outlook Profile
  • Delete Old Calendar Events using VBA
  • Use PowerShell or VBA to get Outlook folder creation date
  • Outlook's Left Navigation Bar
  • Contact's Display Bug
Ajax spinner

Newest Code Samples

Delete Old Calendar Events using VBA

Use PowerShell or VBA to get Outlook folder creation date

Rename Outlook Attachments

Format Images in Outlook Email

Set Outlook Online or Offline using VBScript or PowerShell

List snoozed reminders and snooze-times

Search your Contacts using PowerShell

Filter mail when you are not the only recipient

Add Contact Information to a Task

Process Mail that was Auto Forwarded by a Rule

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in Outlook for Windows.

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




Windows 10 Issues

  • iCloud, Outlook 2016, and Windows 10
  • Outlook Links Won’t Open In Windows 10
  • Outlook can’t send mail in Windows 10: error Ox800CCC13
  • Missing Outlook data files after upgrading Windows?

Outlook Top Issues

  • The Windows Store Outlook App
  • The Signature or Stationery and Fonts button doesn’t work
  • Outlook’s New Account Setup Wizard
  • Outlook 2016: No BCM
  • Exchange Account Set-up Missing in Outlook 2016

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

Outlook-tips.net Samples

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

MSDN Outlook Dev Forum

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Contact Tools

Data Entry and Updating

Duplicate Checkers

Phone Number Updates

Contact Management Tools

Diane Poremsky [Outlook MVP]

Make a donation

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Outlook Suggestion Box (UserVoice)

Slipstick Support Services

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Advertise | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2023 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment