title: display email body of selected email in outlook as a message box in excel?
body: <p>I am using excel 2010 and have created the following vba code which finds emails which contain the word test in their subject heading and then in excel it shows a message box with the body of that email:</p>
  
  <pre><code>Sub GetFromInbox()
  
      Dim olApp As Outlook.Application
      Dim olNs As Outlook.Namespace
      Dim olFldr As Outlook.MAPIFolder
      Dim olItms As Outlook.Items
      Dim olMail As Variant
      Dim i As Long
  
      Set olApp = New Outlook.Application
      Set olNs = olApp.GetNamespace("MAPI")
      Set olFldr = olNs.GetDefaultFolder(olFolderInbox)
      Set olItms = olFldr.Items
      Set objItem = olApp.ActiveExplorer.Selection.Item(1)
  
  
      olItms.Sort "Subject"
  
      i = 1
  
      For Each olMail In olItms
       If InStr(olMail.Subject, "Test") &gt; 0 Then
              MsgBox olMail.Body
              i = i + 1
          End If
      Next olMail
  
      Set olFldr = Nothing
      Set olNs = Nothing
      Set olApp = Nothing
  
  End Sub
  </code></pre>
  
  <p>My ultimate aim here is to add more if conditions to the code, so that only the currently selected email or opened email in outlook has its email body displayed in my excel message box</p>
  
  <p>An example of this is say we have several emails with the subject "test" as it currently stands the code will show the body of all these emails which have the subject "test" one after another in a different message box.</p>
  
  <p>But there should only ever be one message box displayed for the currently selected/opened email in outlook if that emails subject is "test".</p>
  
  <p>Please can someone show me how I can do this? </p>