View Full Version : Macro than would sort by sender name
studmuffin
02-28-2015, 02:05 AM
I would like a macro that would automatically make folder by sender name. When email assigned a catergory it would use a rule with script to move completed email to senders folder. Please respond. I been looking everywhere for this. sounds hard to do but would be helpful.
gmayor
02-28-2015, 07:44 AM
The following will create a folder by sender name (when they arrive if run from a rule) or manually using the testmacro and move the message into that folder.
Option Explicit
Sub TestMacro()
Dim olMsg As MailItem
On Error Resume Next
Set olMsg = ActiveExplorer.Selection.Item(1)
ProcessMessage olMsg
lbl_Exit:
Exit Sub
End Sub
Sub ProcessMessage(olItem As MailItem)
Dim olNS As NameSpace
Set olNS = GetNamespace("MAPI")
AddOutlookFolder olItem.SenderName
olItem.Move olNS.GetDefaultFolder(6).folders(olItem.SenderName)
lbl_Exit:
Set olNS = Nothing
Exit Sub
End Sub
Private Sub AddOutlookFolder(strFolderName)
Dim i As Long
Dim olNS As NameSpace
Dim iFolder As Folder
Dim iNewFolder As Folder
Dim bExists As Boolean
Set olNS = GetNamespace("MAPI")
For i = olNS.GetDefaultFolder(6).folders.Count To 1 Step -1
Set iFolder = olNS.GetDefaultFolder(6).folders(i)
If iFolder.Name = strFolderName Then
bExists = True
Exit For
End If
Next i
If Not bExists Then
Set iFolder = olNS.GetDefaultFolder(6)
iFolder.folders.Add (strFolderName)
End If
Set iFolder = Nothing
Set olNS = Nothing
lbl_Exit:
Set olNS = Nothing
Set iFolder = Nothing
Set iNewFolder = Nothing
Exit Sub
End Sub
studmuffin
02-28-2016, 05:59 PM
Thank you I will try it.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.