title: Save attachments when received. "runtime error:13 Type mismatch"
body: <p>I have several unseen email attachment in email. I would like to download it automatically whenever I receive it from specific sender. I'm using Outlook 2013.</p>
  <p>I get:</p>
  <blockquote>
  <p>runtime error:13 Type mismatch</p>
  </blockquote>
  <pre class="lang-vb prettyprint-override"><code>Private Sub Application_NewMail()
      
      Dim onamespace As Outlook.NameSpace
      Set onamespace = Outlook.GetNamespace(&quot;MAPI&quot;)
      
      Dim myfol As Outlook.Folder
      Set myfol = onamespace.GetDefaultFolder(olFolderInbox)
      
      Dim omail As Outlook.MailItem
      Set omail = Outlook.CreateItem(olMailItem)
      Dim atmt As Outlook.attachment
      
      For Each omail In myfol.Items
      
          If omail.SenderEmailAddress = &quot;@gmail.com&quot; Then
          
              For Each atmt In omail.Attachments
                  
                  atmt.SaveAsFile &quot;C:\Users\raj\Downloads\&quot; &amp; atmt.fileName
                  
              Next
          
          Else
          End If
      
      Next
                  
  End Sub
  </code></pre>