Hi guys,
I am trying to write a bit of code that will loop through my sent items folder and pick out the task status messages that my system is sending.
Within these messages I then want to check whether they have been sent over 14 days previously, if this is the case I would then like the code to delete these task updates.
At present my code is as follows:
Set myolapp = CreateObject("Outlook.Application")
Set myNameSpace = myolapp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderSentMail)
iCount = myFolder.Items.Count
For i = 1 To iCount
Set myMail = myFolder.Items(i)
If (Left(myMail.Subject, 11) = "Task Update") Or (Left(myMail.Subject, 14) = "Task Completed") Or (Left(myMail.Subject, 13) = "Task Accepted") Then
DateSinceCompletion = DateDiff("d", myMail.SentOn, Date, vbMonday)
If DateSinceCompletion > 14 Then
myMail.Delete
iCount = iCount - 1
End If
End If
Next
Set myolapp = Nothing
Set myNameSpace = Nothing
Set myFolder = Nothing
When I run this code it is reporting an object does not support this property or method error. Has anybody got any ideas on what I am doing wrong here?
any help greatly appreciated
Andi
I am trying to write a bit of code that will loop through my sent items folder and pick out the task status messages that my system is sending.
Within these messages I then want to check whether they have been sent over 14 days previously, if this is the case I would then like the code to delete these task updates.
At present my code is as follows:
Set myolapp = CreateObject("Outlook.Application")
Set myNameSpace = myolapp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderSentMail)
iCount = myFolder.Items.Count
For i = 1 To iCount
Set myMail = myFolder.Items(i)
If (Left(myMail.Subject, 11) = "Task Update") Or (Left(myMail.Subject, 14) = "Task Completed") Or (Left(myMail.Subject, 13) = "Task Accepted") Then
DateSinceCompletion = DateDiff("d", myMail.SentOn, Date, vbMonday)
If DateSinceCompletion > 14 Then
myMail.Delete
iCount = iCount - 1
End If
End If
Next
Set myolapp = Nothing
Set myNameSpace = Nothing
Set myFolder = Nothing
When I run this code it is reporting an object does not support this property or method error. Has anybody got any ideas on what I am doing wrong here?
any help greatly appreciated
Andi