title: Email Templates With Variables
body: <p>I'm using code, written with help from this forum, to select a .oft email template from a central repository via a drop down menu.</p>
  
  <pre><code>Public Sub Email_Templates()
  
    With Select_Email_Template
      .Show
      If .Tag &lt;&gt; -1 Then
        CreateItemFromTemplate(Templates(.Tag, FullPath:=True)).Display ' Templates(.Tag) also works
      End If
    End With
    Unload Select_Email_Template
  
  End Sub
  
  Public Function Templates _
                  ( _
                    Optional ByVal plngIndex As Long = -1 _
                  , Optional ByVal NameOnly As Boolean = False _
                  , Optional ByVal FullPath As Boolean = False _
                  ) As Variant
  
    Const strcTemplatesDir As String = "\\c\s\caf1\Digital Delivery Group\DDCOPS\Splunk\Email Templates\"
    Const strcTemplateExtension As String = ".oft"
  
    Static avarTemplateNames As Variant
  
    If IsEmpty(avarTemplateNames) Then
      avarTemplateNames = Array _
      ( _
        "Account Amendment Non SC" _
      , "Amendment SC Application Received" _
      , "Amendment SC" _
      , "Creation Non SC" _
      , "Account Creation SC Application Received" _
      , "Account Creation SC" _
      , "Export Function" _
      , "Password Reset" _
      )
    End If
    If plngIndex &lt;&gt; -1 Then
      If NameOnly = True And FullPath = False Then
        Templates = avarTemplateNames(plngIndex)
      Else
        Templates = strcTemplatesDir &amp; avarTemplateNames(plngIndex) &amp; strcTemplateExtension
      End If
    Else
      Templates = avarTemplateNames
    End If
  
  End Function
  </code></pre>
  
  <p>This is an example of a template:</p>
  
  <blockquote>
    <p>Hi ,</p>
    
    <p>I have been asked to create Splunk account(s) for you in the following
    environment(s).</p>
    
    <p>Your username and password details are:</p>
    
    <p>Username:  Password: </p>
    
    <p>Many thanks and kind regards</p>
  </blockquote>
  
  <p>I'd like to dynamically add the username and password pre the creation of the email.</p>
  
  <p>I really don't want to 'hard code' the email content in the VBA code  because these templates are used by multiple users so if changes need to be made to them these would have to changed multiple times.</p>
  
  <p>Any advice on the best way forward?</p>