Sub FileMessages(Item As Outlook.MailItem)
Dim strFoldername As String, _
olkFolder As Outlook.folder
Select Case Item.SenderName
'Add the following two lines for each sender you want to file messages for.
Case "Holy Devis"
strFoldername = "Holy Devis"
Case "John Doe"
strFoldername = "John Doe"
End Select
If strFoldername <> "" Then
Set olkFolder = OpenOutlookFolder(strFoldername)
Item.Move olkFolder
End If
Set olkFolder = Nothing
End Sub
Function IsNothing(obj)
If TypeName(obj) = "Nothing" Then
IsNothing = True
Else
IsNothing = False
End If
End Function
Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder
Dim arrFolders As Variant, _
varFolder As Variant, _
olkFolder As Outlook.MAPIFolder
On Error GoTo ehOpenOutlookFolder
If strFolderPath = "" Then
Set OpenOutlookFolder = Nothing
Else
If Left(strFolderPath, 1) = "\" Then
strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
End If
arrFolders = Split(strFolderPath, "\")
For Each varFolder In arrFolders
If IsNothing(olkFolder) Then
Set olkFolder = Session.Folders(varFolder)
Else
Set olkFolder = olkFolder.Folders(varFolder)
End If
Next
Set OpenOutlookFolder = olkFolder
End If
On Error GoTo 0
Exit Function
ehOpenOutlookFolder:
Set OpenOutlookFolder = Nothing
On Error GoTo 0
End Function
|