title: How to select IMAP acc in vba Outlook
body: <p>I have a problem, the macro below checks if there is a mail title from the sender. The problem is that in outlook, I have 2 accounts: IMAP and Exchange. Makro always chooses exchange. Where's the reason?</p>
  
  <pre><code> Sub srchmail()
  
  Dim Itms As Items
  Dim srchSender As String
  Dim srchSubject As String
  Dim strFilterBuild As String
  Dim ItmsBuild As Items
  Dim strFilter As String
  
  Set olApp = Outlook.Application
  Set objNS = olApp.GetNamespace("MAPI")
  
  
  Set sub_olFolder = objNS.GetDefaultFolder(olFolderInbox)
  Set sub_olFolder = sub_olFolder.Folders("SUBFOLDER")
  Set Itms = sub_olFolder.Items
  
  Dim i As Long
  For i = 1 To Itms.Count
  Next
  
  
  srchSender = "SENDERMAIL"
  srchSubject = "SUBJECTMAIL"
  
  
  strFilter = "[SenderName] = '" &amp; srchSender &amp; "' And [Subject] = '" &amp; srchSubject &amp; "' And [SentOn] &gt; '" &amp; Format(Date, "dd-mm-yyyy") &amp; "'"
  
  
  Set Itms = Itms.Restrict(strFilter)
  If Itms.Count = 0 Then
  
  
      MsgBox "dont mail in " &amp; sub_olFolder &amp; " with sub:'" &amp; srchSubject &amp; "' on " &amp; Format(Date, "dd-mm-yyyy")
      Else
  
  
      MsgBox "found mail in " &amp; sub_olFolder &amp; " with sub: '" &amp; srchSubject &amp; "' on  " &amp; Format(Date, "dd-mm-yyyy")
  End If
  ExitRoutine:
      Set Itms = Nothing
  End Sub
  </code></pre>