PDA

View Full Version : Category to Folder



chacas
04-26-2018, 02:58 AM
Hi, I work with huge amounts of emails. To make it easier I have created multiple rules to first assign category to the email based on their senders address (this is on receiving them) and then manually move all categories at once to specific folders. I was thinking that maybe I can do this by macro but I have no idea on how outlook macro work. I'm only used to excel macros.

gmayor
04-26-2018, 03:38 AM
Why don't you simply use the rule to move the message to the required folder as it arrives?

chacas
04-26-2018, 04:09 AM
Because I would like to keep all mails in the inbox to make sure not to miss anything. and then once I go through them, move to another folder
So my idea is to create a macro that categorizes the email once received automatically and then triggering another macro to move anything that has a category to a specific folder

gmayor
04-26-2018, 10:51 PM
The easiest solution is to use the Outlook Today screen and add your folders to the list displayed. Then you shouldn't miss any as the list will display unread messages. However the following should work, provided the named folders are direct sub folders of the default inbox and the named folders exist. Change the category names and folder names as appropriate.


Sub MoveCategory()
Dim olItems As Outlook.Items
Dim olItem As Outlook.MailItem
Dim i As Long
Dim strFolder As String
Set olItems = Session.GetDefaultFolder(olFolderInbox).Items
olItems.Sort "[Received]", True
For i = olItems.Count To 1 Step -1
Set olItem = olItems(i)
Select Case olItem.Categories
Case "Category Name 1"
strFolder = "Foldername for Category Name 1"
Case "Category Name 2"
strFolder = "Foldername for Category Name 2"
Case "Category Name 3"
strFolder = "Foldername for Category Name 3"
'etc
Case Else
strFolder = ""
End Select
If Not strFolder = "" Then
olItem.Move Session.GetDefaultFolder(olFolderInbox).folders(strFolder)
End If
Next i
CleanUp:
Set olItems = Nothing
Set olItem = Nothing
lbl_Exit:
Exit Sub
End Sub