Hi
I'm using a macro to save attachments to a number of folders as a new email arrives.
To know if Outlook has done his job I would like to assign the category "Treated" to the new Email.
Outlook does in fact save the attachment to the correct folder but it doesn't assign the category.
I post you a glimpse of the code I'm using
Code:
Private Sub Application_NewMail()
Dim Foldername, FolderDate, FolderDate2, MonthDays As String
Dim objIn As MAPIFolder
Dim objNewMail As MailItem
On Error Resume Next
Set objIn = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
For Each objNewMail In objIn.Items
With objNewMail
If .UnRead = True Then
' REGLES SI DES ATTACHEMENTS SONT PRESENTS
NumberOfAtts = .Attachments.count
If NumberOfAtts > 0 Then
For i = 1 To NumberOfAtts
' SI ATCT
If InStr(1, .Attachments.Item(i).FileName, "ATCT", vbTextCompare) > 0 Then
Foldername = "O:\Regions\ST\ATCT\"
.Attachments.Item(i).SaveAsFile Foldername & .Attachments.Item(i).FileName
'.UnRead = False
.Categories = "traité"
' SI ATRA
ElseIf InStr(1, .Attachments.Item(i).FileName, "ATRA", vbTextCompare) > 0 Then
Foldername = "O:\Regions\ST\"
FolderDate = .Attachments.Item(i).FileName
FolderDate = Mid(FolderDate, InStr(FolderDate, Year(Date) & "-") + 8)
FolderDate = Left(FolderDate, InStr(FolderDate, "-") - 1)
If Len(FolderDate) = 1 Then
FolderDate = "0" & FolderDate
End If
.Attachments.Item(i).SaveAsFile Foldername & FolderDate & "\ATRA\" & .Attachments.Item(i).FileName
'.UnRead = False
.Categories = "traité"
And the rest...
Does anyone know why Outlook won't assign a category?
Btw, as I run the macro from VBA directely it assigns the category, but not when the mail arrives and the attachment is saved.