outlook Prompt for the date

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
789
Office Version
  1. 365
Hi,

Found the code below that is excellent, how can I modify to prompt for the date to retrieve the emails instead of fix date in the code:

VBA Code:
 Sub ExtractMailsFromOutlook()
 
  Dim OutApp As New Outlook.Application 'early binding
  Dim OutNamespace As Namespace, OutFolder As MAPIFolder, OutItem As Object
  Dim r As Integer, cutDate As Date
 
  Set OutNamespace = OutApp.GetNamespace("MAPI")
  Set OutFolder = OutNamespace.GetDefaultFolder(olFolderInbox)
 [B][COLOR=rgb(226, 80, 65)] cutDate = "01/01/2024"[/COLOR][/B]
 
  On Error Resume Next
  For Each OutItem In OutFolder.Items
      If OutItem.ReceivedTime >= cutDate Then
          r = r + 1
          Range("A" & r + 1).Value = OutItem.ReceivedTime
          Range("B" & r + 1).Value = OutItem.SenderName
          Range("C" & r + 1).Value = OutItem.Subject
          Range("D" & r + 1).Value = OutItem.Body
      End If
  Next OutItem
  On Error GoTo 0
 
  Set OutFolder = Nothing
  Set OutNamespace = Nothing
  Set OutApp = Nothing
 
  End Sub

Thank you
 

Forum statistics

Threads
1,226,795
Messages
6,193,045
Members
453,772
Latest member
aastupin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top