PDA

View Full Version : Select The Last 200 of My Inbox



Sentos
01-05-2016, 07:02 PM
Hi Guys,

Can you help me to create a VBA code that will select the last 200 mail in my inbox.

I already have an existing code that will make it a text file later on. It will be my first step and later i will try to schedule that every hour. Hope you can assist me on that.

Regards,

skatonni
01-06-2016, 10:47 AM
Sort is described here http://msdn.microsoft.com/en-us/library/office/ff866960(v=office.15).aspx



Sub Sort_ReceivedTime()

Dim myNameSpace As Namespace
Dim myFolder As folder
Dim myItems As Items

Dim iCount As Long
Dim i As Long

Set myNameSpace = GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myItems = myFolder.Items

myItems.sort "[ReceivedTime]", True

iCount = myItems.count
If iCount > 200 Then iCount = 200

For i = 1 To iCount
Debug.Print i & ": " & myItems(i).subject & "-- " & myItems(i).ReceivedTime
Next I

ExitRoutine:
Set myNameSpace = Nothing
Set myFolder = Nothing
Set myItems = Nothing

Debug.Print "Done."

End Sub