, , , ,

I have a few rules that categorize emails as I receive them based on Subject Line contents. Two of them Categorize emails into either “Tickets” or “Outages” categories.
I need these emails to appear in my inbox when they first arrive because they may be actionable. However, at points throughout my week, I find myself cleaning my inbox by scrolling Ctrl-selecting multiple emails and then moving them manually to a folder (tickets or outages, respectively), when the emails are no longer relevant.

I got sick of this and made (customized an existing, see below) a VBScript macro that will move all categorized emails to their folder.

See below for the script. Change appropriate variable names as needed for your own. Thanks to cytop’s post (http://goo.gl/VY2VNH) for some of the logic re-tooling.

‘Outlook VB Macro to move selected mail item(s) to a target folder

Sub MoveToFiled()
On Error Resume Next

Dim ns As Outlook.NameSpace
Dim moveToFolder As Outlook.MAPIFolder
Dim objItem As Outlook.MailItem

Set ns = Application.GetNamespace(“MAPI”)

‘Define path to the target folder
Set moveToFolder = ns.Folders(“mfield@nextdigital.ca”).Folders(“8 – Tickets”)

If moveToFolder Is Nothing Then
MsgBox “Target folder not found!”, vbOKOnly + vbExclamation, “Move Macro Error”
End If

Set FolderInbox = ns.GetDefaultFolder(olFolderInbox)

For Each objItem In FolderInbox.Items
If InStr(objItem.Categories, “Tickets”) > 0 Then
If objItem.Class = olMail Then
objItem.Move moveToFolder
End If
End If

Set objItem = Nothing
Set moveToFolder = Nothing
Set ns = Nothing

End Sub