title: Get email from Outlook to Excel specified by received date
body: <p>I am creating a macro to get email by subject and received date in our team shared box.</p>
  
  <p>I use for loop to check all email in mailbox but it takes forever because my statement checks 1000+ mails.</p>
  
  <p>How can I get email by specific date? Let's say I need email 12/1/2017 to 12/30/2017.</p>
  
  <p>The key is using Restrict method but I don't know how I can use it.</p>
  
  <pre><code>Sub GetFromOutlook()
  Dim OutlookApp As Outlook.Application
  Dim OutlookNamespace As Namespace
  Dim Folder As MAPIFolder
  Dim OutlookMail As Variant
  Dim i As Integer
  
  Set OutlookApp = New Outlook.Application
  Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
  
  Dim olShareName As Outlook.Recipient
  Set olShareName = OutlookNamespace.CreateRecipient("sharemailbox@example.ca")
  Set Folder = OutlookNamespace.GetSharedDefaultFolder(olShareName, olFolderInbox).Folders("sharebox subfolder").Folders("sharebox subfolder2")
  
  i = 1
  
  For Each OutlookMail In Folder.Items
  
      If ((Range("From_Date").Value &lt;= OutlookMail.ReceivedTime) And _
        (OutlookMail.ReceivedTime &lt;= Range("To_Date").Value)) And _
        OutlookMail.Sender = "sender@example.com" Then
  
          Range("eMail_subject").Offset(i, 0).Value = OutlookMail.Subject
          Range("eMail_date").Offset(i, 0).Value = OutlookMail.ReceivedTime
  
          i = i + 1
  
      End If
  
  Next OutlookMail
  
  Set Folder = Nothing
  Set OutlookNamespace = Nothing
  Set OutlookApp = Nothing
  
  End Sub
  </code></pre>
  
  <p>I assume the code I have to fix is:</p>
  
  <pre><code>&lt;For Each OutlookMail In Folder.Items&gt;
  </code></pre>
  
  <p>How can I make statement using Restrict Method?</p>