title: How to get Outlook Email received time
body: <p>I need to extract attachments from Emails received in a user preferred time frame. </p>
  
  <p>Say like extract for Emails received between 2PM to 4PM. </p>
  
  <p>Please find the below code I've that extract files perfectly - but it did for all the Emails in the folder. </p>
  
  <p>Please help me to resolve it.</p>
  
  <pre><code>Sub Unzip()
  
      Dim ns As NameSpace             'variables for the main functionality
      Dim Inbox As MAPIFolder
      Dim SubFolder As MAPIFolder
      Dim Atchmt As Attachment
      Dim FileName As Variant
      Dim msg As Outlook.MailItem
  
  
      Dim FSO As Object               'variables for unzipping
      Dim oApp As Object
      Dim FileNameFolder As Variant
      Dim Totalmsg As Object
      Dim oFrom
      Dim oEnd
  
      Set ns = GetNamespace("MAPI")
      Set Inbox = ns.GetDefaultFolder(olFolderInbox)
      Set SubFolder = Inbox.Folders("TEST")
      Set Totalmsg = msg.ReceivedTime
      oFrom = InputBox("Please give start time", ("Shadowserver report"))
      oEnd = InputBox("Please give End time", ("Shadowserver report"))
  
     If Totalmsg &lt;= oFrom And Totalmsg &gt;= oEnd Then
     For Each msg In SubFolder.Items
              For Each Atchmt In msg.Attachments
                      If (Right(Atchmt.FileName, 3) = "zip") Then
                      MsgBox "1"
  
                                      FileNameFolder = "C:\Users\xxxx\Documents\test\"
                                      FileName = FileNameFolder &amp; Atchmt.FileName
                                      Atchmt.SaveAsFile FileName
                                      Set oApp = CreateObject("Shell.Application")
                                      oApp.NameSpace(FileNameFolder).CopyHere oApp.NameSpace(FileName).Items
  
                                      Kill (FileName)
                                      On Error Resume Next
                                      Set FSO = CreateObject("scripting.filesystemobject")
                                      FSO.deletefolder Environ("Temp") &amp; "\Temporary Directory*", True
                      End If
               Next
      Next
  End If
  End Sub
  </code></pre>