title: Outlook 2007 - VBA macro in NormalEmail.dotm
body: <p>I have a Word 2007 template that I use as Normal.dotm, which has corporate theme, styles, etc., plus a tiny bit of macro code that overrides the default behaviour of the bullet &amp; number buttons on the ribbon.</p>
  
  <p>I'd now like to use this same template when creating emails in Outlook 2007. I've tried just copying my Normal.dotm to NormalEmail.dotm, and to an extent this works, but although my macro is correctly <em>invoked</em> when I press the bullet/number buttons in the email editor, it gives an error:</p>
  
  <blockquote>
    <p>Run time error 429: ActiveX component can't create object</p>
  </blockquote>
  
  <p>On further investigation, it seems that anything I do within my macro that references an object in the normal Word object model (Application, Selection, etc.) causes this error. So, even if my macro consists of the following, it still fails:</p>
  
  <pre><code>MsgBox TypeName(Application)
  </code></pre>
  
  <p>I have an inkling that this is because I'm running in the context of Outlook, not Word, and so perhaps there is no (Word) application, or any of the objects associated with it. I know that the email editor in Outlook is Word-but-not-as-we-know-it-Jim.</p>
  
  <p>Having said that, I did discover that ThisDocument <em>does</em> return a valid Document object; unfortunately, it corresponds to the template itself, not the email being edited.</p>
  
  <p>By trial and error, I've discovered that I can get at the Document corresponding to the email by the following circuitous route (this displays the text in the email):</p>
  
  <blockquote>
    <p>MsgBox ThisDocument.MailEnvelope.Item.Application.ActiveInspector.WordEditor.Content.Text</p>
  </blockquote>
  
  <p>However, this code also seems to cause Outlook to crash - not at the time, but later, when you close Outlook.</p>
  
  <p>At this point, I'm just about ready to admit defeat. No doubt the "correct" way to create macros in Outlook is to create them in Outlook itself, but from my limited experience, that's just <em>horrible</em>. (You can create macros in VBA, but you can't deploy them; or, you can create them in VSTO, but then you need an installer rather than simply deploying a template).</p>
  
  <p>So. Any ideas out there that would let me do all that I hoped to do?</p>
  
  <ol>
  <li>Override the behaviour of the bullet/number buttons on the ribbon in the email editor.</li>
  <li>Deploy the macros in the NormalEmail.dotm file, rather than having to "install" them.</li>
  <li>Not crash Outlook.</li>
  </ol>