Thanks for your suggestion.I modifed one of the scripts to help me move the emails for the last 2 days. Open the VBA Editor by pressing Alt+F11 on your keyboard. In Outlook 2007 and older, it’s at Tools, Macro Security.Īfter you test the macro and see that it works, you can either leave macro security set to low or sign the macro. To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. OlMeetingCancellation, olMeetingRequest, _įirst: You will need macro security set to low during testing. It also allows you to use different dates for each group of items types.
This code sample uses Case statement to get the ReceivedTime or CreationTime of email, meeting requests and responses, as well as read receipt reports, then plugs the date value into the calculation. Use Case Statements instead of IF statements ' 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 ' 102, 103, 104 are replied, forwarded, reply all Lastaction = propertyAccessor.GetProperty(lastverb)
Set propertyAccessor = objVariant.propertyAccessor
Because Reply, Reply all, and Forward values are 102, 103, and 104, and to the best of my knowledge, those are the only possible values, we can leave the lastaction value at 7 (was intDateDiff in the original macro). and objVariant.Move lines with the code block below. Using the first macro on this page as the base, replace the code block between the If objVariant.Class. With a few simple changes, you can convert the macro above to move messages that were replied to or forwarded.īegin by adding these lines to the top of the macro with the other Dim statements.ĭim propertyAccessor As Outlook.propertyAccessor Set objDestFolder = GetFolderPath("my-data-file-name\Inbox") When I add a macro that uses a function, I can easily see if I have that function already. Tip: A function can be used by any macro, so I keep the functions together in a separate module. That line is the only change needed to use a different data file (well, that line and the function). If you want to move the messages to a new data file, you need to change the destination folder path: Set objDestFolder = to use the GetFolderPath function: Set objDestFolder = GetFolderPath("new-pst-file\folder-name"). MsgBox "Moved " & lngMovedItems & " messages(s)." ' Display the number of items that were moved. IntDateDiff = DateDiff("d", objVariant.SentOn, Now) Set objDestFolder = objSourceFolder.Folders("Old")įor intCount = To 1 Step -1 Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderInbox) Set objNamespace = objOutlook.GetNamespace("MAPI") The Date field can either be SentOnor ReceivedTime when you are working with email or meeting request and responses.ĭim objSourceFolder As Outlook.MAPIFolder Tested in Outlook 2010 and Outlook 2013 with an Exchange mailbox. You'll need to change this as well as the folder path you are moving the email to. In this sample, the data file name is an email address because that is what Outlook 2010 uses for data file names. You'll also need to replace the data file name. You'll need to set the age, in days, to your desired number. This code sample checks the default Inbox for email older that 7 days and moves any it finds to a subfolder of the Inbox, called Old. " Macro to file Outlook email by sender's display name" has versions that file into folders by name, domain, or date. The code sample gives you the code needed to move only messages you've replied to or forwarded.
The third macro on this page shows you how to use a Select Case statement to move different Outlook items types, using a different age for each item type. Two macros show you how to move messages to a folder within your current data file and to move messages to a folder in a new data file.
There are 4 macros on this page plus one code snippet. If you aren't a big fan of moving mail, you can leave it in the Inbox and use custom views to hide older mail.