PDA

View Full Version : Solved: Macro not working to delete mail at specific Hour from specific folder



guatelize
06-16-2011, 02:43 AM
Hello
I'm having trouble to get this macro work to delete from a specific Inbox subfolder "My Folder" after 4 hours from current time containing a specific subject string "RawData" :

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, "RawData")) Then
myItem.Delete
End If

Next
End Sub

Thanks for your help

JP2112
06-29-2011, 06:38 PM
Please use code tags when posting VBA code.

'... your code here ...

I would use this approach: http://www.vbaexpress.com/forum/showthread.php?t=35985

Essentially, 'start the clock' by creating a task reminder four hours later, then when the BeforeReminderShow event occurs, check to see if it's for the same reminder, then call your code.

guatelize
07-05-2011, 07:08 AM
Thanks for your help