Run a script rule
To use the code, you'll create a rule with the desired conditions and choose 'run a script' as the only action, selecting this script.
Sub KeepFriday(Item As Outlook.MailItem) datefri = WeekdayName(Weekday(aItem.ReceivedTime)) If datefri = "Friday" Then 'moves to the Friday subfolder under Inbox. Item.Move Session.GetDefaultFolder(olFolderInbox).Folders("Friday") Else Item.Delete End If End Sub
VBA to run anytime
To use this code sample select the folder then run the macro
Sub KeepFridayOnly() Dim dest As Outlook.MAPIFolder Dim aItem As Object Dim datefri As String Set mail = Application.ActiveExplorer.CurrentFolder For Each aItem In mail.Items datefri = WeekdayName(Weekday(aItem.ReceivedTime)) If datefri = "Friday" Then aItem.Move Session.GetDefaultFolder(olFolderInbox).Folders("Friday") End If Next aItem Set aItem = Nothing Set myolApp = Nothing End Sub
Process mail by date and time
Outlook's Rules and Search functions can't search by times. While you can "do something" with messages (or any Outlook item) between two dates, you can't filter by time too. However, you can use VBA to "do something" messages that fall within a certain time period.
In this code sample, I'm adding a category to messages that arrived after 6 PM during the last 30 days. This macro runs on the messages in the selected folder.
Sub FlagByTime() Dim aItem As Object Dim strTime As String Set mail = Application.ActiveExplorer.CurrentFolder For Each aItem In mail.Items 'Check the message age If aItem.ReceivedTime > Date - 30 Then strTime = TimeValue(aItem.ReceivedTime) 'Check the received time If strTime > #6:00:00 PM# Then aItem.Categories = "Nighttime" aItem.Save End If End If Next aItem Set aItem = Nothing End Sub
More Run a Script Samples:
- Autoaccept a Meeting Request using Rules
- Automatically Add a Category to Accepted Meetings
- Convert RTF Messages to Plain Text Format
- Create a rule to delete mail after a number of days
- Delegates, Meeting Requests, and Rules
- Forward meeting details to another address
- How to Change the Font used for Outlook's RSS Feeds
- Keep Canceled Meetings on Outlook's Calendar
- Move messages CC'd to an address
- Outlook AutoReplies: One script, many responses
- Outlook's Rules and Alerts: Run a Script
- Read Outlook Messages using Plain Text
- Receive a Reminder When a Message Doesn't Arrive?
- Run a Script Rule: Change Subject then Forward Message
- Run a script rule: Reply to a message
- Run a Script Rule: Send a new message when a message arrives
- Run Rules Now using a Macro
- Sort messages by Sender domain
- Use a Rule to delete older messages as new ones arrive
- Use a run a script rule to mark messages read
- Use VBA to move messages with attachments