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

VBA UserForm sample: Select from a list of templates

Slipstick Systems

› Developer › Code Samples › VBA UserForm sample: Select from a list of templates

Last reviewed on January 6, 2018     67 Comments

This is a version of the macro and userform from Select from a list of subjects before sending a message and uses a userform to display a list of templates to select from to create a new message to the selected contact.

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. Create a userform and add controls to it
  4. Right click on the Command button and choose Properties.
  5. Type OK (or Use Template) in the Caption field.
  6. Type btnOK in the (Name) field.
  7. add controls to a user form

  8. Right click on the UserForm and choose View Code.
  9. Paste the code below into the code window.
  10. Change the Template display names as desired. This list is for your reference only, not the actual template file name. The filename is set in the VBA macro code.

Private Sub UserForm_Initialize()
  With ComboBox1
    .AddItem "Potential client"
    .AddItem "New client welcome letter"
    .AddItem "Work order approval"
    .AddItem "Existing client"
    .AddItem "Payment overdue"
    .AddItem "Invoice"
  End With
End Sub

Private Sub btnOK_Click()
    lstNum = ComboBox1.ListIndex
    Unload Me
End Sub

Note, you will need to have a reference to the Forms library in Tools, References.
Add the forms library as a reference
If you receive a "User-defined type not defined" you are missing the reference to Microsoft Forms 2.0 Object Library. If its not listed, add C:\Windows\System32\FM20.dll or C:\Windows\FM20.dll as a reference.

Macro to call the UserForm

  1. Right click on Project1 and choose Insert > Module.
  2. Paste the code below into the Module.
  3. Change the template filenames in strTemplate.

Select a contact then run the macro to test it.

Public lstNum As Long

Public Sub ChooseTemplate()

Dim oMail As Outlook.MailItem
Dim oContact As Outlook.ContactItem

If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then
 Set oContact = ActiveExplorer.Selection.Item(1)

Dim strTemplate As String
   UserForm1.Show

    Select Case lstNum
    Case -1
'  -1 is what you want to use if nothing is selected
         strTemplate = "template-1"
    Case 0
         strTemplate = "template-1"
    Case 1
        strTemplate = "template-2"
    Case 2
         strTemplate = "template-3"
    Case 3
         strTemplate = "template-4"
    Case 4
         strTemplate = "template-5"
    End Select

    strTemplate = "C:\Users\me\Templates\" & strTemplate & ".oft"
    Set oMail = Application.CreateItemFromTemplate(strTemplate)

With oMail
  .To = oContact.Email1Address
  .ReadReceiptRequested = True
  .Subject = "My Macro test"
  .Body = "Hi " & oContact.FirstName & "," & vbCrLf & vbCrLf & oMail.Body
  .Display
End With
  End If
Set oMail = Nothing

End Sub

Video tutorial

Create a toolbar button

You can create a ribbon or QAT button for the ChooseTemplate macro so it's easier to start the macro.

More Information

How to use Outlook's VBA Editor

VBA UserForm sample: Select from a list of templates was last modified: January 6th, 2018 by Diane Poremsky

Related Posts:

  • Select from a List of Subjects before Sending a Message
  • Do you send a lot of messages to one person or group and want to make
    How to create preaddressed messages
  • Add Email Addresses to a Contact Group
  • Save Selected Email Message as .msg File

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
67 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Paul Rhoades (@guest_217246)
December 1, 2020 3:12 pm
#217246

Is there a way to use the drop down list and adding a macro to find a saved email template based on what the user selects from the drop down?

1
0
Reply
Jake (@guest_214953)
March 25, 2020 6:23 am
#214953

hey hi, can any one tell me how to retrieve the mail id`s and info of the mail in the customized user form when we click on event send.

0
0
Reply
Doug (@guest_213598)
July 12, 2019 3:10 pm
#213598

I tried to copy your code but the form does not load with the drop down values. What might I be looking for>

Get Object required in the initialization code

0
0
Reply
RichardE (@guest_213289)
May 21, 2019 10:14 pm
#213289

hello Diane,
I would like to have 3 modules that each require access to the same form (frmStationery) to select an option from a list. I have been able to avoid 'Ambiguous name detected by making
each module having their own public string....Public stationery1 ....stationery3;
Form:-
Private Sub ok_click()
Stationery1 = filePath & Me.ListBox.Text
Stationery2 = filePath & Me.ListBox.Text
Stationery3 = filePath & Me.ListBox.Text
Me.Hide
End Sub

Module1:-
Public stationery1
Sub macroGetStationery()
frmStationery.Show
If Stationery1 = "" Then Exit Sub
Unload frmStationery
....
End Sub
I just can't work out how I can do it. Do you have any suggestions?

0
0
Reply
Richard (@guest_213000)
April 1, 2019 6:40 pm
#213000

hello Diane, thanks for all the code & how-to's you've provided thus far.
Is it possible to create 1 userform for more than 1 macro? If yes...how?
Thank you

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Richard
May 23, 2019 10:34 am
#213299

Yes, you can call 1 userform from multiple macros - this line is all you need: UserForm1.Show. You will may need to use variables to pass a unique value to it.

Using the macro on this page as an example, instead of hard coding the template names, you could use global variables to set it, depending on which macro called the template. The macro sets the variable and they are passed to the form.

Private Sub UserForm_Initialize()
With ComboBox1
.AddItem strOne
.AddItem StrTwo
End With

and
Dim strTemplate As String
strOne = "Whatever"
strTwo = "Something else"

UserForm1.Show

0
0
Reply
Bhushan Gaikwad (@guest_212604)
January 27, 2019 2:24 pm
#212604

Hi Diane,

I am trying to create a macro for public folder in which I would be able to assign emails to Associates of my team. For eg. From non-assigned emails in sequence, I want to assign 4 emails to X, 5 emails to Y & 3 emails to Z.
Any assistance for this is greatly appreciated!!!

0
0
Reply
Joseph (@guest_212571)
January 21, 2019 5:57 am
#212571

I am using office 365. Using VBA code is it possible to create 3 question form send to 10 customers and get their reply back from them. We didn't buy license for Microsoft forms or don't want to use survey monkey, would like to use via outlook and VBA. Please help me on this.

0
0
Reply
Dan S (@guest_209648)
December 14, 2017 10:54 am
#209648

Diane
I am also having the problem where the value for lstnum is not getting passed back to the main macro. I do have "Public lstnum as long" at the top of the macro. I can see the value in the locals window but once i step back to the main macro, the lstnum variable is gone. Any ideas?

1
0
Reply

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

Latest EMO: Vol. 30 Issue 16

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
  • Disable "Always ask before opening" Dialog
  • Adjusting Outlook's Zoom Setting in Email
  • This operation has been cancelled due to restrictions
  • How to Hide or Delete Outlook's Default Folders
  • Reset the New Outlook Profile
  • Save Attachments to the Hard Drive
  • Add Attachments and Set Email Fields During a Mail Merge
  • Outlook SecureTemp Files Folder
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
  • Classic Outlook is NOT Going Away in 2026
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

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Classic Outlook is NOT Going Away in 2026

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 © 2025 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