title: How to handle non-email when importing Outlook email data into Excel with VBA?
body: <p>I'm trying to import all mails received and sent the past year.</p>
  <p>For the received mails works, but the code stops when importing the sent mails. Specifically for the <code>OutlookMail.To</code> property. It stops when it gets to an accepted invitation for a meeting that I have sent.</p>
  <p>Is there a way to bypass all the accepted invitations that I have sent and only get the emails?</p>
  <pre class="lang-vb prettyprint-override"><code>Sub GetFromOutlook()
  
  Dim OutlookApp As Outlook.Application
  Dim OutlookNamespace As Namespace
  Dim Folder1 As MAPIFolder
  Dim Folder2 As MAPIFolder
  Dim OutlookMail As Variant
  Dim i As Integer
  
  Set OutlookApp = New Outlook.Application
  Set OutlookNamespace = OutlookApp.GetNamespace(&quot;MAPI&quot;)
  Set Folder1 = OutlookNamespace.GetDefaultFolder(olFolderInbox)
  Set Folder2 = OutlookNamespace.GetDefaultFolder(olFolderSentMail)
  
  i = 1
  
  For Each OutlookMail In Folder1.Items
      If OutlookMail.ReceivedTime &gt;= Range(&quot;H5&quot;).Value And OutlookMail.ReceivedTime &lt;= Range(&quot;I5&quot;).Value Then
          Range(&quot;C4&quot;).Offset(i, 0).Value = OutlookMail.Subject
          Range(&quot;A4&quot;).Offset(i, 0).Value = OutlookMail.ReceivedTime
          Range(&quot;B4&quot;).Offset(i, 0).Value = OutlookMail.SenderName
          i = i + 1
      End If
  
  j = 1
  
  Next OutlookMail
  
  For Each OutlookMail In Folder2.Items
      If OutlookMail.ReceivedTime &gt;= Range(&quot;H5&quot;).Value And OutlookMail.ReceivedTime &lt;= Range(&quot;I5&quot;).Value Then
          Range(&quot;f4&quot;).Offset(j, 0).Value = OutlookMail.Subject
          Range(&quot;d4&quot;).Offset(j, 0).Value = OutlookMail.ReceivedTime
          Range(&quot;E4&quot;).Offset(j, 0).Value = OutlookMail.To
          
          j = j + 1
      End If
  Next OutlookMail
  
  Set Folder1 = Nothing
  Set Folder2 = Nothing
  Set OutlookNamespace = Nothing
  Set OutlookApp = Nothing
      
  End Sub
  </code></pre>