delete Inbox message at specific Hour

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")
 
P

perseeni peppu

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top