title: How to run code to automate email template?
body: <p>I am trying to fill placeholder text in an Outlook email.</p>
  <p>I started with a simplified version of the code at <a href="https://www.ablebits.com/office-addins-blog/2021/04/21/outlook-email-templates-fillable-fields-dropdown/" rel="nofollow noreferrer">https://www.ablebits.com/office-addins-blog/2021/04/21/outlook-email-templates-fillable-fields-dropdown/</a>.<br />
  When I hit &quot;run&quot; it prompts me with the &quot;Macro Name&quot; dialog box.<br />
  If I type a name and hit &quot;Create&quot;, it creates a new, blank module with no association to the code.</p>
  <p>How can I get the code to run from the &quot;ThisOutlookSession&quot;?</p>
  <p>My goal is to run this macro with a specific email template I created, &quot;NewOrderNotification&quot;, to facilitate filling in standard data.</p>
  <pre class="lang-vb prettyprint-override"><code>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 = &quot;New SO XXXXX for Quote XXXXXX / [CUSTOMER] - [CITY, STATE]&quot; Then
       
  'Check message format
  If mail.BodyFormat = OlBodyFormat.olFormatPlain Then
  
  '--------
  'Replace [_SO] with the entered value
  If InStr(mail.Body, &quot;[_SO]&quot;) &gt; 0 Then
      Value = InputBox(&quot;Enter the new sales order #&quot;)
           
  If Value &lt;&gt; &quot;&quot; Then
      mail.Body = Replace(mail.Body, &quot;[_SO]&quot;, Value)
  End If
  End If
  '---------
           
  'Repeat the code block above for the other fields in the email
  
  Set mail = Nothing
    
  End If
  End Sub
  </code></pre>