Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Sub ListMail()
Dim oApp As Outlook.Application
Dim oNS As NameSpace
Dim oRecItems As Outlook.MAPIFolder
Dim oFilterRecItems As Items
Dim oNewMail As Outlook.MailItem
Dim strFilter As String
Dim dteLastCheck As Date
Dim dteThisCheck As Date
Dim strNewMessage As String
Dim i
'Check last 30 days emails
dteLastCheck = DateAdd("d", -30, Now())
dteThisCheck = Now()
Set oApp = CreateObject("Outlook.Application")
Set oNS = oApp.GetNamespace("MAPI")
Set oRecItems = oNS.GetDefaultFolder(olFolderInbox)
strFilter = "[ReceivedTime] > " _
& Chr(34) & Format(dteLastCheck, "dd/mm/yyyy hh:nn") & Chr(34) _
& " AND [ReceivedTime] < " _
& Chr(34) & Format(dteThisCheck, "dd/mm/yyyy hh:nn") & Chr(34)
Set oFilterRecItems = oRecItems.Items.Restrict(strFilter)
'Print results to the immediate window.
Debug.Print = "Number of emails: " & oFilterRecItems.Count & vbCrLf
For i = 1 To oFilterRecItems.Count
Debug.Print _
oFilterRecItems(i).ReceivedTime & vbCrLf _
& oFilterRecItems(i).To & vbCrLf _
& oFilterRecItems(i).EntryID & vbCrLf ' _
& oFilterRecItems(i).Body & vbCrLf
Next
Set oFilterRecItems = Nothing
Set oNS = Nothing
Set oApp = Nothing
End Sub