How to make Outlook email template with fillable fields, variables and dropdown lists

Three ways to create an email template with variables, text field or dropdown list that will ask for the values to fill in before sending out an email.

If replying to repetitive emails is part of your daily routine, then most likely you are using Outlook templates to automate this part of your work. But what if your template contains some variables that you need to change before an email goes off. Editing data manually is not the best way, as there is always a chance you may forget to update some important details. So, the question is - how do I create a template that will prompt me to enter the information and automatically insert it into the appropriate place in a message? The get the answer, please continue reading :)

Make Outlook email template with variables using VBA

This example shows how to insert variable information in an email template using a macro. To keep things simple, I've created this small template with two fields to enter in a message body, [date] and [percent].

Outlook email template with two variables

And here is the VBA code that will ask for the values to fill in based on the subject of the email:

Private WithEvents m_Inspectors As Outlook.Inspectors
Private WithEvents m_Inspector As Outlook.Inspector
 
Private Sub Application_Startup()
 Set m_Inspectors = Application.Inspectors
End Sub
 
Private Sub m_Inspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
 If TypeOf Inspector.CurrentItem Is Outlook.MailItem Then
  'Handle emails only
  Set m_Inspector = Inspector
 End If
End Sub
 
Private Sub m_Inspector_Activate()
 
 Dim Item As MailItem
 Dim Value As String
 
 If TypeOf m_Inspector.CurrentItem Is MailItem Then
 
    Set mail = m_Inspector.CurrentItem
 
    'Identify the message subject
    If mail.Subject = "Your subscription expires soon" Then
    
        'Check message format
        If mail.BodyFormat = OlBodyFormat.olFormatPlain Then
 
            'Replace [date] with the entered value
            If InStr(mail.Body, "[date]") > 0 Then
             Value = InputBox("Enter the expiry date")
        
             If Value <> "" Then
              mail.Body = Replace(mail.Body, "[date]", Value)
             End If
            End If
        
            'Replace [percent] with the entered value
            If InStr(mail.Body, "[percent]") > 0 Then
               Value = InputBox("Enter percentage discount")
        
             If Value <> "" Then
                mail.Body = Replace(mail.Body, "[percent]", Value)
             End If
            End If
        
        Else
            
            'Replace [date] with the entered value
            If InStr(mail.HTMLBody, "[date]") > 0 Then
             Value = InputBox("Enter the expiry date")
        
             If Value <> "" Then
              mail.HTMLBody = Replace(mail.HTMLBody, "[date]", Value)
             End If
            End If
        
            'Replace [percent]; with the entered value
            If InStr(mail.HTMLBody, "[percent]") > 0 Then
               Value = InputBox("Enter percentage discount")
        
             If Value <> "" Then
                mail.HTMLBody = Replace(mail.HTMLBody, "[percent]", Value)
             End If
            End If
        
        End If
 
    End If
 
    Set mail = Nothing
 
 End If
End Sub

For each variable mentioned in the code, a separate input box will be displayed:

The user is asked to enter a value in the input box.

The values you enter in the boxes will appear exactly where they should in the message:

The values entered in the boxes will appear in the message.

How this macro works

There are two key points in the code that you should take notice of:

  • The template is identified by its subject. In our case, it's " Your subscription expires soon". Be sure to replace this text with the subject of your template.
  • In our sample code, there are two placeholders, [date] and [percent]. You can modify them as needed. Please pay attention that there are 4 instances of each placeholder in the code, not counting comments, and all of them should be replaced with your own placeholders. If you have more variables, then add a similar block of code for each of them (please see the code parts with the corresponding comments).

How to create an email template with variables using the macro

Here's a short summary of the steps to make an email template with variables and send a message based on the template:

  1. Create a new email, insert the text in the message body, put placeholders where needed, and fill in the Subject line with some unique text that is going to be used only in the subject of this specific template.
  2. Save your message as Outlook template (*.oft). For the detailed instructions, please see How to create an email template in Outlook.
  3. Press Alt + F11 to open the VBA editor, paste the macro's code into the ThisOutlookSession module, and save the project (Ctrl + S).
  4. Restart Outlook.
  5. Create an email message based on the template you've just created. The detailed steps can be found here: How to send a message based on an email template.
  6. In each input box, type the value you are asked for.
  7. Review the finalized message and hit Send.

Email template with variables not working

If the VBA code does not work as expected or does not work at all in your Outlook, it's likely to be one of these reasons:

  1. You have not restarted Outlook after inserting the code in the VBA editor. Outlook restart is required to execute the code in the Startup event handler.
  2. Mail.Subject in your code does not correspond to the subject of your template.
  3. The placeholders in the code are not exactly same as in your template.
  4. Macros are disabled in your Outlook. To check this, please click File > Options > Trust Center > Trust Center Settings > Macro Settings and select either:
    • Notifications for all macros
    • Enable all macros (not recommended)

    Please be aware that the second option allows all macros to run, including potentially malicious codes, so it is safer to choose the first one.

Create Outlook email template with fillable fields

Now, let's explore a different approach to the same task. This time we are going to use our own tool named Shared Email Templates for Outlook. If you have never heard of it before, here is a one-sentence intro:

Shared Email Templates is an Outlook add-in to quickly create your own collection of templates with predefined or fillable fields, custom formatting, images, and attachments.

What makes it different from. oft templates? This example will show you :)

With Shared Email Templates installed in your Outlook, carry out these steps to create a fillable template:

  1. On the add-in's pane, select the target folder and click the New Template button.

    If the text you want to include in your template is in the message you are composing, select that text, and then click New Template. The selected text will be inserted into your template automatically.

    Creating a new email template

  2. If we wanted a simple text template, we could click Save right away, and our job would be completed. But you do want a field where you can enter some information, so it will be automatically inserted in the appropriate place in the message, right? So, let's go make the first one.

    In the template's text, select your placeholder (<date> in our case), and click the Insert Macro button. If there is no placeholder in your template, then put the cursor exactly where your value should be inserted.

    Inserting a macro in place of the placeholder

  3. In the list of macros, find WhatToEnter and click on it.

    Inserting the WhatToEnter macro in the template

  4. Choose the field type (Date in our case), type the window title (usually, some meaningful name for the value to enter) and click Insert.

    Configuring a date field

  5. As the result, a properly configured macro is inserted in your template as shown in the screenshot:

    A properly configured macro is inserted in the email template.

    You can now save your template or add a few more macros if you have more than one fillable field.

  6. As our template has one more placeholder (<%>), we select it and click the Insert Macro icon again. This time we choose Text in the first box, type the corresponding window title, and click Insert.

    Configuring a fillable text field

  7. Apply some formatting to your template if needed, name it and save.

    A fillable email template for Outlook

Done! Your fillable email template for Outlook is good to go.

Note. Shared Email Templates macros are not VBA macros. They are kind of placeholders in a template that are replaced with corresponding values in a message. All functional code is executed on the add-in's side, so there is no need to enable macros in your Outlook.

How to use an email template with input fields

Preparing an email template for sending out is as easy as it could possibly be. To insert a template into a message, double-click on it or click the Paste icon on the left.

Double-click a template to insert it into a message.

A small form will show up asking you to pick a date from a dropdown calendar and enter a percentage discount in the text box:

Filling in the template fields

A moment later, your message with all the necessary information is ready to be sent:

The message is ready to be sent.

Tip. Want to automatically fill in the Subject line or To, Cc and Bcc fields? Shared Email Tempalte's macros can do all this and a lot more things!

The steps to add a dropdown list to your email template are the same as described above. The only difference is step 4 where you configure the What To Enter fields:

  • In the first box, choose Dropdown list.
  • In the Window Title box, put some text that will remind you what kind of value you will be selecting (Number of days before expiry in our case).
  • In the Items box, type the dropdown values one per line.

To be able to enter a value other than in the dropdown list, select the User can edit selected items checkbox. To limit the input to the predefined items, leave this box unselected.

Configuring a dropdown list for an email template

The finalized macro that will trigger our dropdown list takes this form:

~%WhatToEnter[3;5;10;{title:"No. of days before expiry",editable}]

If any changes are needed at a later point, you can edit the dropdown items directly in the template without recreating the macro from scratch.

In a similar fashion, we insert one more macro for the percentage discount. In this case, we limit the choices to only the items in the drop-down list (the User can edit selected items checkbox is unselected):

Configuring a second dropdown list

After all these customizations, our Outlook email template with two dropdown lists looks as follows:

Outlook email template with two dropdown lists

When inserting the template in a message, the following form will appear asking you to select both values:

When inserting the template in a message, pick a value from a dropdown.

It was a quick demonstration of just one capability of Shared Email Templates. You can find plenty more useful features on the above linked page. Curious to give it a try? Download a free version from Microsoft AppSource.

That's how you can create an email template with fillable or dropdown fields. Thank you for reading and hope to see you on our blog next week!

Other ways to reply with template in Outlook: