title: Using Excel VBA to create email in Outlook 2010 from template
body: <p>I have code that worked well in Excel/Outlook 2003 on XP, I'm now running Windows 7 Excel/Outlook 2010 and receive an error:</p>
  
  <blockquote>
    <p>Run-time error '287': Application-defined or object-defined error.</p>
  </blockquote>
  
  <p>My code is based on this answer in:
  <a href="https://stackoverflow.com/questions/8469960/send-an-email-from-excel-2007-vba-using-an-outlook-template-set-variables">Send an email from Excel 2007 VBA using an Outlook Template &amp; Set Variables</a></p>
  
  <p>I'm creating my outlook object and mailitem like this:</p>
  
  <pre><code>Dim MyOlApp
  Dim MyOlItem
  Set MyOlApp = CreateObject("Outlook.Application")
  Set MyOlItem = MyOlApp.CreateItemFromTemplate(Range("oftLocation").Value) 'user defined location
  </code></pre>
  
  <p>The error appears after I reference <code>MyOlItem</code>, the code is replacing references in the <code>.htmlBody</code></p>
  
  <p>Amending to <code>.Body</code> makes no difference, same error shows.</p>
  
  <p>My references in VBA are set to:</p>
  
  <ul>
  <li>VBA </li>
  <li>Microsoft Excel 14.0 Object Library </li>
  <li>OLE Automation</li>
  <li>Microsoft Office 14.0 Object Library </li>
  <li>Microsoft Forms 2.0 Object Library</li>
  <li>Microsoft Scripting Runtime</li>
  </ul>