delete Inbox message at specific Hour

  • Thread starter Thread starter nina
  • Start date Start date
N

nina

would someone please post an example of how a message could be deleted from inbox at a
certain hour containing a specific subject string

ie. Hour > 23 and InStr(Subject,"Joined Domain")
 
Public Sub InboxItemCheck()
Dim myNamespace As Outlook.NameSpace
Dim myAppts As Outlook.Items
Dim myItems As Outlook.Items
Dim myItem As Object
Dim i As Long
Dim DateStart As Date
Dim DateToCheck As String

DateStart = Date
DateToCheck = "[LastModificationTime] >= """ & DateStart & """"

Set myNamespace = Application.GetNamespace("MAPI")
Set myAppts = myNamespace.GetDefaultFolder(olFolderInbox).Items
Set myItems = myAppts.Restrict(DateToCheck)
For i = myItems.Count To 1 Step -1
Set myItem = myItems.Item(i)
If (InStr(myItem.Subject, "Joined Domain")) Then
myItem.Delete
End If

Next
End Sub
 
Back
Top