title: Reply to last email from specific sender in Excel
body: <p>In Excel, I am looking up the email address of a person, and then I want to find the last email (send or received) and trigger a reply to this email. This reply is triggered by a button in Excel.</p>
  <pre><code>Dim a As Integer
  Dim objOutlook As Object
  Dim objMail As Object
  Dim rngBody As Range
  Dim rngAttach As Range
  
  Set objOutlook = CreateObject(&quot;Outlook.Application&quot;)
  Set objMail = objOutlook.CreateItem(0)
  
  
  EmailStr = &quot;sombody@gmail.com&quot; (dummy replacement for my find the email adress in excel spreadsheet
  </code></pre>
  <p>then I would need to find emails to/from this address in my outlook, and then reply to the latest one.</p>
  <p>What I did manage is start a new email to this person, but no idea how to find and reply</p>
  <pre><code> With objMail
          .To = EmailStr
          .CC = AMEmail
          .Subject = TitleMail
             .HTMLBody = BodyStr &amp; Signature
          .ReadReceiptRequested = True
      
          .Display 'Instead of .Display, you can use .Send to send the email _
                      or .Save to save a copy in the drafts folder
          
  
      Set objOutlook = Nothing
      Set objMail = Nothing
      Set rngBody = Nothing
      Set rngAttach = Nothing
  </code></pre>
  <p>Update: still struggling, but no more crashes for now. Wher I am stuck now it here:</p>
  <pre><code>Private Sub CommandButton2_Click()
  
  Dim olApp As Object
  Dim olNs As Object
  Dim olFldr As Object
  
  Dim olItems As Object
  Dim olItemReply As Object
  Dim i As Long
  
  Dim emailStr As String
  Dim filter As String
  
  Set olApp = CreateObject(&quot;Outlook.Application&quot;)
  
  Set olNs = olApp.GetNamespace(&quot;MAPI&quot;)
  Set olFldr = olNs.GetDefaultFolder(6) ' olFolderInbox
  Debug.Print &quot;olFldr: &quot; &amp; olFldr
  
  emailStr = &quot;sombody@gmail.com&quot; '(email address in Excel spreadsheet)
  Debug.Print &quot;emailStr: &quot; &amp; emailStr
  
  Set olItems = olFldr.Items
  Debug.Print olItems.Count
  'finds all 19 items in my inbox with msgbox(olItems.count)
  
  
  filter = &quot;[SenderEmailAddress] = '&quot; &amp; emailStr &amp; &quot;'&quot;
  Debug.Print filter
  
  Set olItems = olFldr.Items.Restrict(filter)
  Debug.Print olItems.Count
  
  'finds 0 items now ??? why....
  
  End sub
  </code></pre>