

I have a macro that looks up a folder - but i have not used it nested folders - all of the folders were under Inbox\Clients\. If intDateDiff >= 0 Then sSenderName = Right(objVariant.SenderEmailAddress, Len(objVariant.SenderEmailAddress) - InStr(objVariant.SenderEmailAddress, If sSenderName = " " Then sSenderName = objVariant.SenderName End If On Error Resume Next Set objDestFolder = objNamespace.Folders("OutlookEmail").Folders(sSenderName) 'Set objDestFolder = objDestFolder.Folders(sSenderName) If objDestFolder Is Nothing Then Set objDestFolder = objNamespace.Folders("OutlookEmail").Folders.Add(sSenderName) End If objVariant.Move objDestFolder 'count the # of items moved lngMovedItems = lngMovedItems + 1 Set objDestFolder … Read more » Public Sub MoveSelectedToDomain() Dim objOutlook As Outlook.Application Dim objNamespace As Outlook.NameSpace Dim objDestFolder As Outlook.MAPIFolder Dim objSourceFolder As Outlook.Folder Dim currentExplorer As Explorer Dim Selection As Selection Dim obj As Object Dim objVariant As Variant Dim lngMovedItems As Long Dim intCount As Integer Dim intDateDiff As Integer Dim strDestFolder As String Set objOutlook = Application Set objNamespace = objOutlook.GetNamespace("MAPI") Set currentExplorer = objOutlook.ActiveExplorer Set Selection = currentExplorer.Selection Set objSourceFolder = currentExplorer.CurrentFolder For Each obj In Selection Set objVariant = obj If objVariant.Class = olMail Then intDateDiff = DateDiff("d", objVariant.SentOn, Now) ' I'm using 40 days, adjust as needed. Hello Diane, Could you please help in modifying the following script, so that it creates a subfolder with the sender name in the 'domain' folder? For e.g email from folders will be /test/ This will be very helpful for many people. Set objDestFolder = objParentFolder.Folders(sSenderName) Set objParentFolder = objNS.GetDefaultFolder(olFolderInbox) Private Sub objItems_ItemAdd(ByVal Item As Object) Set objWatchFolder = objNS.GetDefaultFolder(olFolderInbox) Set objNS = Application.GetNamespace("MAPI") Private WithEvents objItems As Outlook.Items To use SMTP address, change SenderName to SenderEmailAddress, note however, that if you use Exchange server, you will need to get the Exchange SMTP.

This ItemAdd macro runs as messages hit the default inbox and file messages to a subfolder of the Inbox, by the sender's display name. Set objDestFolder = objSourceFolder.Folders(intYear) IntDateDiff = DateDiff("d", objVariant.ReceivedTime, Date)ĭebug.Print objVariant.Subject & "-" & intYear
Outlook 365 color code emails by sender how to#
This code snippet shows how to file messages by year, moving only those messages that are older than a year. ' uses email addresses for datafile names ' the example uses an email address because Outlook 2010 ' use your datafile name and each folder in the path Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderInbox)įor intCount = To 1 Step -1 Using the sender's email address would eliminate this problem, but make it harder to know who each folder is for.ĭim objSourceFolder As Outlook.MAPIFolder If the sender uses different email clients, the messages may be filed in several folders. It looks for the display name, and if a folder does not exist, it creates it. This version of the macro moves messages to an Inbox subfolder named for the sender. MsgBox "Moved " & lngMovedItems & " messages(s)." ' Display the number of items that were moved. ' Set objDestFolder = objInbox.Folders(sSenderName) ' Use These lines if the destination folder is not a subfolder of the current folderįolders("Inbox") ' or whereever the folder is SSenderName = objVariant.SentOnBehalfOfName IntDateDiff = DateDiff("d", objVariant.SentOn, Now) Set objSourceFolder = currentExplorer.CurrentFolder Set Selection = currentExplorer.Selection Set currentExplorer = objOutlook.ActiveExplorer Set objNamespace = objOutlook.GetNamespace("MAPI") This version of the macros works on the selected message(s) and creates a subfolder in the current folder.

While I'm not a big fan of filing messages in hundreds of folders, I can see the value in filing some messages. I have a rather large list of words and I want the emails to move to certain folders if any of those words are present in the subject.Set objDestFolder = objSourceFolder.Folders(sSenderName) I am looking for someone to write a quick script that can allow me to sort emails into different folders based on certain words in the subject.
