• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Select from a List of Subjects before Sending a Message

Slipstick Systems

› Developer › Select from a List of Subjects before Sending a Message

Last reviewed on August 14, 2016     36 Comments

OutlookForum member X82 needs to change the subject of replies.

Instead of the subject reading "RE: Info", I must change it to a pre-set sentence like Authorization 0054213. The number will change but the first part is always the same. Is there a way of making outlook change the subject line?

A quick but "dirty" method is to use an InputBox to select a number, which then inserts the correct subject. (The code for this is at Change subject)

It's also possible to do this using a ComboxBox, but its more complicated and requires a UserForm.

Before using the macro, you need to set Outlook's macro security to Low or to warn. Then open the VBA editor using Alt+F11. More information on using the VBA editor is at How to use the VBA Editor

For a variation of the code that contains a proper Cancel command, see cancel-subjects.txt. Follow the instructions below, but add a second command button to the Userform and change the caption to Cancel.

Step 1: Create the Userform.

  1. Right click on Project1 and select Insert > UserForm
  2. Open the control Toolbox and select a ComboBox and add it to the UserForm.
  3. Add a Command button.
  4. Right click on the Command button and choose Properties.
  5. Type OK (or Change Subject) in the Caption field.
  6. Right click on the UserForm and choose View Code.
  7. Paste the code below into the code window.
  8. Change the subject titles as desired. This list is for your reference only, not the actual text that will be added to the subject. The subject text is changed in the VBA macro code.
Private Sub UserForm_Initialize()
  With ComboBox1
    .AddItem "Subject 1"
    .AddItem "Subject 2"
    .AddItem "Subject 3"
    .AddItem "Subject 4"
    .AddItem "Subject 5"
    .AddItem "no change"
End With
End Sub

Private Sub CommandButton1_Click()
    lstNo = ComboBox1.ListIndex
    Unload Me
End Sub

Create a userform and add controls to it

Step 2: Add VBA macro for reply

Next you need to add the macro that creates the reply then asks you to select the new subject.

  1. Right click on Project1 and choose Insert > Module.
  2. Paste the code below into the Module.
  3. Change the subject lines to use the desired text. If you want to include the original subject, use oMail.Subject = "Subject " & objMail.Subject format.

To test, select a mail item and run the macro. The macro works with a selected or open message, thanks to the use of the GetCurrentItem function.

Public lstNo As Long

Public Sub ChangeSubjectOnReply()

Dim objItem As Object
Dim oMail As Outlook.MailItem

Set objItem = GetCurrentItem()
Set oMail = Application.ActiveExplorer.Selection(1).Reply

 oMail.Display
   
   UserForm1.Show

  '  MsgBox "user chose " & lstNo & " from combo"

    Select Case lstNo
    Case -1
         oMail.Subject = objItem.Subject
    Case 0
         oMail.Subject = "Subject 1"
    Case 1
        oMail.Subject = "Subject 2"
    Case 2
       oMail.Subject = "Subject 3"
    Case 3
       oMail.Subject = "Subject 4"
    Case 4
       oMail.Subject = "Subject 5"
    End Select
End Sub



Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application
          
    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select
      
    Set objApp = Nothing
End Function

Video Tutorial

Import a ready to use form

Because this is more complicated than just pasting a macro, I have ready to use code available for download. Import it into the VBA editor and it's ready to run. ChangeSubject VBA

 

More Information

The second part of X82's question was how to get a code from the message body and add it to the subject. To do this you need to find the code in the body. You can do this by parsing the body and looking for a string. Basic instructions are at Parse text fields using VBA. For best results, it needs to be in the body in the same location, eg, as "Authorization: 123456789". Once you find the code and assign it to a string value, enter it into the subject using this format:
oMail.Subject = "Authorization " & strCode

VBA UserForm sample: Select from a list of templates

Select from a List of Subjects before Sending a Message was last modified: August 14th, 2016 by Diane Poremsky
Post Views: 46

Related Posts:

  • VBA UserForm sample: Select from a list of templates
  • Outlook VBA: Use a Text File to Populate a ListBox
  • Selectively change message format when replying
  • This macro copies a meeting request to an appointment. Why would you w
    Copy meeting details to an Outlook appointment

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.

Comments

  1. Gabriela says

    February 8, 2022 at 11:41 am

    Hi Diane,
    This script is similar with what I would need and It would be great if you could help me out to adapt it to my need.
    I will have an open email that I intend to forward (manually click send) to a certain email address, always the same one, but the subject line differs for each email. I want to enter a certain number in the combo box, and a certain subject to be auto-populated. Could you please help me with codding for this one?
    Would be much appreciated!
    Thank you!

    Reply
  2. Sameer says

    December 12, 2019 at 10:33 pm

    How to use dynamic subject list?

    Reply
  3. Aaron Bolton says

    October 1, 2018 at 8:15 pm

    Hi, I have used this code to setup a macro to add subject from a drop down. As per the example it works by selecting a contract and running the macro which works fine, however I would like to also be able to select a contact group to populate the To. It does not work when I do try to do this, is there a way I can make it work for a contract group?

    Thanks

    Reply
  4. Jake says

    August 18, 2018 at 5:19 pm

    Hi Diane,

    If I will place the value I have from the combobox on the email body, how am I going to format it (font size, font style, bold)?

    Thank you

    Reply
  5. Athena Passos says

    June 29, 2017 at 7:18 pm

    Diane,

    I'm trying to use the combobox to allow user to select between a list of carriers,
    like "Carrier 1", "Carrier 2" and "Carrier 3", and based in the selection, the macro
    populates the "To" field in the email with the respective emails for the carrier.
    Is that possible?

    Reply
    • Diane Poremsky says

      June 29, 2017 at 8:28 pm

      Sure. In the combo box, you put the carrier names and in the Select case, you'd use oMail.To = "alias@address".

      Reply
  6. Jerald Nicholas says

    October 9, 2016 at 3:16 am

    Dear Diane,

    Thanks a lot for the effort.
    This is the one I am looking for a long time.
    I would like to add some more things for my project. Please tell me how to set up hotkey(ALT+T) to run a macro in OUTLOOK 2013.

    Looking forward for your reply

    Thanks
    Jerald Nicholas

    Reply
  7. Ashwin Mathew says

    August 14, 2016 at 8:03 pm

    Hi Diane,

    Thanks for this tutorial, I have this working with some minor modifications. I wanted to ask, is there any way to launch the macro when creating a new email in outlook? Instead of going through the developer tab ever time, I'd like to macro to run and prompt me for the subject line whenever I create a new email. Will be great if you can advise on this.

    Thank you,
    Ash

    Reply
    • Diane Poremsky says

      August 14, 2016 at 9:42 pm

      As long as the macro is one you run (not an automatic macro that runs when something happens) you can create a button on the ribbon for it. See https://www.slipstick.com/developer/how-to-use-outlooks-vba-editor/#button if you aren't sure how to do it.

      Reply
  8. Ashwin Mathew says

    August 14, 2016 at 1:00 pm

    Hi Diane,

    Thanks for this tutorial, I got this working pretty well with some modifications. I wanted to ask, is there any way to trigger this macro anytime a new email is created in outlook. Meaning I'd want the form where I select the subject lines to appear when I click "New Mail Message", instead of going through the developer tab ever time.

    Thanks,
    Ash

    Reply
    • Diane Poremsky says

      August 14, 2016 at 4:33 pm

      You need to use the newinspector - see https://www.slipstick.com/developer/code-samples/default-subject-messages/ for an example. I think (did not test) you'd add UserForm1.Show and select case lines to the newinspector macro.

      Reply
    • Diane Poremsky says

      August 14, 2016 at 4:53 pm

      This is working here -
      Declare this in a new module (if you have other modules already in use, put it at the top of one)
      Public lstNo As Long

      Use the macros at the page i linked to and replace the inspector active macro with this
      Private Sub m_Inspector_Activate()
      Dim strSubject as String
      Select Case lstNo
      Case -1
      strSubject = objItem.Subject
      Case 0
      strSubject = "Subject 1"
      Case 1
      strSubject = "Subject 2"
      Case 2
      strSubject = "Subject 3"
      Case 3
      strSubject = "Subject 4"
      Case 4
      strSubject = "Subject 5"
      End Select

      If TypeName(m_Inspector.currentItem) = "MailItem" And _
      m_Inspector.currentItem.Subject = "" Then
      m_Inspector.currentItem.Subject = strSubject
      End If
      Set m_Inspector = Nothing
      End Sub

      Reply
  9. Konrad says

    March 29, 2014 at 2:14 am

    Thank you Diane for this tutorial. I was looking for such thing for a long time. I have couple of data files (*.pst)with folders created in them. Every folder name is a specific number assigned to specific topic. I was thinking, could you kindly write macro that lists folder names from all datafiles connected with Outlook, and after selecting, putting it to new e-mail subject?

    Reply
    • Diane Poremsky says

      March 31, 2014 at 12:04 am

      Scanning folders to create an array of names and using that list of names in a dialog box is not a simple project, especially if you need to check multiple data files. Sorry.

      Reply
  10. Gareth says

    November 11, 2013 at 3:22 am

    Hey Diane. Last question I promise. Is there any way to add a Timer to the UserForm. Ideally I would like it that if the UserForm has been open for 30 seconds and the user has not selected a subject it closes?

    Reply
    • Diane Poremsky says

      November 11, 2013 at 9:29 am

      There isn't a timer control, but it should be possible using the Win32 API. Use timer code, such as this sample and call it from the userform.

      Reply
  11. Gareth says

    October 4, 2013 at 1:42 am

    hey Diane I've pretty much got this working perfectly now. one issue I'm having, when the user types an email and clicks "Send" the pop-up dialogue is displayed asking the user to pick the pre-fix of their subject. I've noticed that the user can continue to type in the email whilst the form pop-up is shown, is there a way to disable typing in the email until the user selects something from the pop-up? thanks for all your help it's been greatly appreciated!

    Reply
    • Diane Poremsky says

      October 4, 2013 at 8:24 pm

      No, not that i have found that works with the email form.

      Reply
  12. Karolina says

    July 23, 2013 at 3:21 am

    Hi Danielle / All,

    I've done everything as listed above but I keep getting the below message when running the macro. Please can you suggest what might need correcting?

    Run-time error: '424'

    Object Required

    Reply
    • Diane Poremsky says

      July 29, 2013 at 10:55 pm

      sorry for taking so long - I went on vacation and had a pile of comments to go through. :( Which line does it stop on?

      Reply
      • Charles says

        December 8, 2016 at 11:29 am

        I am getting the same error
        it is this line

        Set oMail = Application.ActiveExplorer.Selection(1).Reply

  13. Gareth says

    June 13, 2013 at 5:47 pm

    thanks so much diane for taking the time to help, changing the reply to createitem worked, but still not exactly what i'm looking. is it not possible to have a userform load on the click of the "send" button, prompting for a subject to be selected, with a cancel button? really do appreciate all your help.

    Reply
    • Diane Poremsky says

      June 14, 2013 at 5:27 am

      if you want it to kick in on every message, you need to use the reply event:
      Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)

      See copy attachments for sample code - try switching out the code in the reply macro.

      Reply
  14. Gareth says

    June 12, 2013 at 8:05 pm

    hi diane, thanks for your quick replies. that worked a treat! well sort of, it works ok on replying to an email. is it possible to run this on a new email? basically what i need is whenever someone clicks "send", regardless, new email, or reply they need to select from the dropdowns, but they also need the option to cancel. thanks again.

    Reply
    • Diane Poremsky says

      June 13, 2013 at 10:21 am

      If you want to run the macro and create a new message, replace
      Set oMail = Application.ActiveExplorer.Selection(1).Reply

      with Set oMail = Application.CreateItem(olMailItem)

      To take over the New button, you need to use code similar to the code at the bottom of this page. Use something like this instead of the appt code:

      If TypeName(m_Inspector.CurrentItem) = "MailItem" And _
      m_Inspector.CurrentItem.Subject = "" Then
      ' do whatever
      End If

      Reply
      • Camil says

        January 9, 2017 at 3:03 pm

        Hey Diane.

        I got the above code to work I change couple of thing like I want to run this on new message in Outlook.. I'm need to know how to put a default recipient in the "to" field on the email.. select the request type from the combo box when you click "ok" it put the subject in correct but I'm need to set a default email address once that macro run.. Is there anyway to do this..

      • Diane Poremsky says

        March 4, 2017 at 1:35 am

        if you are using 1 address, omail.to = "email@address" will work, if you are adding an address, using the recipient collection to add it:
        Dim objRecip As Recipient
        Set objRecip = Item.Recipients.Add("email@address")
        objRecip.Type = olTo

  15. Gareth says

    June 12, 2013 at 5:11 pm

    Hey Diane,
    this doesn't appear to work. When I click cancel the UserForm closes but it sends the email anyway? What I need is:
    - user types an email - >clicks "Send"
    - a UserForm then Pops-Up where the user must select a "Subject" (from a dropdown)
    - if they click "OK" the email sends with the subject listed added to the start of their subject
    - if they click "Cancel" the UserForm closes but the email remains on screen and doesn't send (allowing them to make a change to the email if required). Is this do-able? If so could you maybe create a tutorial. It would be greatly appreciated. I'm so close to getting it! Thanks

    Reply
    • Diane Poremsky says

      June 12, 2013 at 7:36 pm

      It *should* work the way you want - it did here. Try the code at cancel-subjects.txt - it has a proper Cancel added.

      Reply
  16. Gareth says

    June 12, 2013 at 1:16 am

    is it possible to add a cancel button to this? what i'm trying to create is a pop-up, when the person tries to send an email they must select a subject classification from a dropdown. If they select one it then adds itself to the start of their subject, if they click cancel the pop-up window closes but the email remains on screen. is this possible?

    Reply
    • Diane Poremsky says

      June 12, 2013 at 5:51 am

      Yes, it is possible to cancel. Add a cancel button (Command button) and use this code:
      Private Sub CommandButton2_Click()
      Unload UserForm1
      End Sub

      Reply
  17. Andy McCarthy says

    May 8, 2013 at 7:25 pm

    Thank you - yes, it's a control on a contact form, not a userform. I'm also reviewing the other links you posted. One I had already been through but couldn't quite make the connection to what I wanted. I appreciate your help!!

    Reply
  18. Diane Poremsky says

    May 8, 2013 at 3:02 pm

    Also, see https://support.microsoft.com/kb/290819 - it's applicable in all versions.

    This too - http://www.outlookcode.com/archive0/d/formcontrols.htm

    Reply
  19. Andy McCarthy says

    May 8, 2013 at 7:40 am

    Hi Diane - I'm trying to apply the above in a different scenario: populating a custom contact form's field with a numeric value based on what I select from a combobox in that same custom form. I have the combobox populated using myComboBox.AddItem and bound to "Profession." These "Professions" are various positions in my organization. I would like another field to auto-populate with a numeric value based on the Profession chosen. It's a weighting system we use. I need to load these weight values as well. At some point I'd like to learn how to use tables somehow to make updating the combobox list and the associated weight values easier, but for now, I'm completely stumped on how where to input the numeric weights and then to make the field's value dependent upon the combobox selection. Would you please point me in the right direction? As always, thank you very much!

    Reply
    • Diane Poremsky says

      May 8, 2013 at 2:57 pm

      This is with a Combobox control on a contact's form, not a userform, correct?

      Reply
  20. Andy McCarthy says

    May 7, 2013 at 3:01 pm

    Hello Diane - I'm trying to modify the above to do something I think should be simpler (I hope). I inserted a combo box (bound to Profession field) to my custom contacts form and added this script (I have many items but only included one in this message):

    Sub Item_Open()
    Dim myComboBox
    Set myComboBox = Item.GetInspector.ModifiedFormPages("Employee").Controls("Specialty")
    myComboBox.AddItem("Specialty1")
    End Sub

    I'd like each "Specialty" to have a numeric weight associated and populate another field with that weight, based on what I select from the combobox. Would you please point me in the right direction for populating a field from a combobox selection?

    Thanks!

    Andy

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

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

Latest EMO: Vol. 31 Issue 7

Subscribe to Exchange Messaging Outlook






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?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • Reset the New Outlook Profile
  • Disable "Always ask before opening" Dialog
  • This operation has been cancelled due to restrictions
  • Change Outlook's Programmatic Access Options
  • How to Hide or Delete Outlook's Default Folders
  • Use Public Folders In new Outlook
  • Removing Suggested Accounts in New Outlook
  • How to Delete Stuck Read Receipts
  • Sync Issues and Errors with Gmail and Yahoo accounts
  • Error Opening iCloud Appointments in Classic Outlook
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
Ajax spinner

Recent Bugs List

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

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

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

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

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.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

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

Other Microsoft 365 applications and services




New Outlook Articles

Sync Issues and Errors with Gmail and Yahoo accounts

Error Opening iCloud Appointments in Classic Outlook

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

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

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

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

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

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

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

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 | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

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