Outlook Open Email Templates | VBA Macro #9

Share on facebook
Share on twitter
Share on linkedin
Outlook Email templates are great! Opening Outlook email templates not so great. That is why we create the Open Email Templates macro. This Outlook macro will help you quickly access your default email template file path giving you access to all of your created Outlook Email Templates. An Input Box will appear with all of your available email templates with a unique leading number. Simply type the leading number of the email template you want to display and click to Ok to open it. This Outlook macro is designed to grow with you over time and will display all of your email templates as you continue to create them. The Open Email Templates macro puts your email templates at your fingertips. Stop spending time opening email template and start using them efficiently and effectively today!

See it in Action!

Watch this video to see this macro in action.

The Code

Here is the code behind this macro.
'Leverage & Lean "Less Clicks, More Results"
Sub OpenEmailTemplates()
' Means variable is in use
Dim Counter As Integer '
Dim DisplayFiles As String '
Dim FolderPath As String '
Dim NewItem As Outlook.MailItem '
Dim oFSO As Object '
Dim oFolder As Object '
Dim oFile As Object '
Dim TemplateName As String '
Dim TemplateNumber As Integer '
Dim User As String '

On Error GoTo LeverageLean

User = (Environ$("Username"))
FolderPath = "C:\Users\" & User & "\AppData\Roaming\Microsoft\Templates\" 'Default Outlook Email Template path. You can update the FolderPath to somewhere else.

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(FolderPath)

Counter = 1
 
For Each oFile In oFolder.Files 'Loop through every File in FolderPath
If oFile.Type = "Outlook Item Template" Then 'If the File is an .oft add to DisplayFiles
DisplayFiles = DisplayFiles & vbNewLine & Counter & ". " & Left(oFile.Name, Len(oFile.Name) - 4)
Counter = Counter + 1
End If
Next oFile

If Len(DisplayFiles) > 1023 Then 'If DisplayFiles exceeds the character limit display MsgBox
MsgBox ("You have exceeded the character limit of the InputBox. " & _
"Email templates that should be available for selection will not be able to display. " & _
"Try making the file names of your email templates shorter. " & _
"Navigate to your folder path here: " & FolderPath)
End If

TemplateNumber = InputBox(DisplayFiles, "Outlook Email Templates") 'Determine what Email Template to open

Counter = 1

For Each oFile In oFolder.Files 'Loop through every File in FolderPath
If oFile.Type = "Outlook Item Template" Then 'If the File is an .oft
If Counter = TemplateNumber Then 'If the Counter is the same as the selected Template
TemplateName = oFile.Name 'Selected Email Template File Name
End If
Counter = Counter + 1
End If
Next oFile
 
Set NewItem = Application.CreateItemFromTemplate(FolderPath & "\" & TemplateName)
NewItem.Display 'Open the selected Email Template path

Set NewItem = Nothing
Set oFSO = Nothing
Set oFolder = Nothing
Set oFile = Nothing

Exit Sub

LeverageLean:
If Err.Number = 76 Then
MsgBox ("Something went wrong. Ensure the Folder Path is correct. " & vbNewLine & "Don't hesitate to email me: brentschneider@leveragelean.com")
ElseIf TemplateNumber = 0 Or TemplateNumber > Counter - 1 Then
Exit Sub
End If

End Sub
'Stay Awesome!

Macro Instructions

Watch this video to get started using this macro.

Customization

These lines of code can be customized to personalize this macro.
18 FolderPath = “C:\Users\” & User & “\AppData\Roaming\Microsoft\Templates\” ‘Default Outlook Email Template path. You can update the FolderPath to somewhere else.
32 If Len(DisplayFiles) > 1023 Then ‘If DisplayFiles exceeds the character limit display MsgBox (You won’t be able to see all of your template selection options. Try making the file names of your templates short to resolve this issue.)

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 Access, Excel, Outlook, PowerPoint, 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
Subscribe as an Insider to receive additional rights.
If you like our content and want to show your support tip us here!

Contact Us

Looking to improve your computer processes?
Leverage & Lean is here to help!

Leverage & Lean

Is focused on improving computer processes by Leveraging programming and applying Lean principles. It is our goal to make you more efficient and effective on your computer producing “Less Clicks and More Results!”