Sub CheckMail()
Dim olApp As Outlook.Application
Dim olNS As NameSpace
Dim olRecItems As Outlook.MAPIFolder
Dim olFilterRecItems As Items
Dim olNewMail As Outlook.MailItem
Dim strFilter As String
Dim dteLastCheck As Date
Dim dteThisCheck As Date
Dim strNewMessage As String
Dim i
'Dates for testing
dteLastCheck = DateAdd("d", -30, Now())
dteThisCheck = Now()
'Outlook Application and Namespace
Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")
'Outlook Inbox
Set olRecItems = olNS.GetDefaultFolder(olFolderInbox)
'Filter for Restrict. Note that there are no seconds
'and that the date is a string.
strFilter = "[ReceivedTime] > " _
& Chr(34) & Format(dteLastCheck, "mm/dd/yyyy hh:nn") & Chr(34) _
& " AND [ReceivedTime] < " _
& Chr(34) & Format(dteThisCheck, "mm/dd/yyyy hh:nn") & Chr(34)
'Restrict the mails in the Inbox by the filter
Set olFilterRecItems = olRecItems.Items.Restrict(strFilter)
'Build a new mail body from filtered mails
strNewMessage = "Number of mails: " & olFilterRecItems.count & vbCrLf
For i = 1 To olFilterRecItems.count
strNewMessage = strNewMessage & olFilterRecItems(i).Body & vbCrLf
Next
'New mail
Set olNewMail = olApp.CreateItem(olMailItem)
With olNewMail
.To = "a@b.c"
.Subject = "Emails"
.Body = strNewMessage
.Display
End With
'Reminder
dteLastCheck = dteThisCheck
End Sub