title: Error While Sending Email through Outlook from Excel VBA
body: <p>I have write a macro in outlook and excel vba, the description are:
  1. Code in Outlook for Open Excel file if email subject line match :</p>
  
  <pre><code>Private Sub Items_ItemAdd(ByVal Item As Object)
      If TypeOf Item Is Outlook.MailItem Then
          '// Subject line here
          If InStr(Item.Subject, "Run Dashboard") Then
              Call openExcel
          End If
      End If
  End Sub
  </code></pre>
  
  <p>Once Excel is open and dashboard has run then email has to be sent via excel.</p>
  
  <p>vba and code:</p>
  
  <pre><code>Dim outapp As Object
  Dim nmail As Object
  
  Set outapp = CreateObject("Outlook.Application")
  Set nmail = outapp.CreateItem(0)
  With nmail
      .To = "xxxxxx@xxxx.com"
      .cc = ""
      .bcc = ""
      .Subject = flname
      .htmlbody = RangetoHTML(Range("A1:" &amp; Split(Cells(, lastcol1).Address, "$")(1) &amp; lastrow1))
      .attachments.Add ActiveWorkbook.FullName
      .display
  End With
  
  On Error GoTo 0
  
  Set nmail = Nothing
  
  Set outapp = Nothing
  </code></pre>
  
  <p>Now I am facing the error on <code>Set outapp = CreateObject("Outlook.Application")</code> 
  This error is only showing if i open excel file through outlook email as mentioned in point 1, if i open file in normal way i.e. without outlook help, then code is running successfully.</p>
  
  <p>Please help in the same.</p>
  
  <p>Thanks in advance</p>