Hello all. I'm writing a VBA script to extract the email subject from certain mails. I want to extract the title and then add a UserProperty "Read" to the mails to ensure that the script does not consider them again.
However, this does not seem to be working because every time I restart the macro, the already read mails get read again and again. What could be going wrong?
Also, how do I set a default value for the UserProperty?
Here is my code :
Code:
Sub myOlApp_NewMail()
Dim WordArray() As String
k = 0
l = 0
Dim myOlApp As New Outlook.Application 'Application Outlook
Set MonNSpace = myOlApp.GetNamespace("MAPI")
Set FldDossier = MonNSpace.PickFolder
Debug.Print "New run"
For i = FldDossier.Items.Count To 1 Step -1
On Error Resume Next
If Mail.Subject = "Read Me" Then
Set CheckProperty = MonMail.UserProperties.Find("Read")
If CheckProperty.Value = "No" Then
Property = Mail.UserProperties.Add("Read", olText)
Property.Value = "Yes"
Mail.Save
Debug.Print "Mail not read"
Else
Debug.Print "Mail read"
Next i
End Sub