title: Excel VBA for searching in mails of Outlook
body: <p>I'm working on a project where I have a list of Account IDs, and what I'm trying to do is to create a macro that will interface with Outlook, search my Inbox for any email with an specific criteria, and then return "Y" or "N" if it was found, and if it was found, who the email was sent from and the time it was sent. Below is the code I'm using; I need the macro to search the Body of the Email instead of the Subject Line. When I substitute [Subject] for [Body], the macro runs without errors, but returns no emails (I place a couple test emails for it to catch). I am running Excel and Outlook 2007, and have already reference the MS 12.0 Excel &amp; Outlook libraries in VBA.</p>
  
  <pre><code>Sub Work_with_Outlook()
  
      Set outlookApp = CreateObject("Outlook.Application")
  
      Dim olNs As Outlook.Namespace
      Dim Fldr As Outlook.MAPIFolder
      Dim olMail As Variant
      Dim sir() As String
  
      Set outlookApp = New Outlook.Application
      Set olNs = outlookApp.GetNamespace("MAPI")
      Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
      Set myTasks = Fldr.Items
  
      Set olMail = myTasks.Find("[Subject] = ""123456""")
      If Not (olMail Is Nothing) Then
          olMail.Display
      End If
  
  End Sub
  </code></pre>