Move received & sent mail to folders based on Contacts

O

Onno Willems

Hi there,

I have a large number of people I sent mail to and get mail from
(professionally). I have made folders in my pst for each category of contact
(say sales, management, technical, personal) and then sub folders for each
person.

I want to move all mail I sent to a person and receive from to the
corresponding folder. How do I achieve this? I know I can set up rules for
this (I already have a bunch), but I'm talking about > 150 people here. I
have to create 2 rules for each person (on for messages being sent, other
for received). Doing this using the Outlook UI would takes ages. I have
tried to export the rules, but they are in some binary format (no XML there
sadly, that would make it much easier to create&maintain).

So I guess I have to program something myself? (I know my way around VBA but
are not familiar with the Outlook object model....) Any tips?

Thanks,
Onno
 
E

Eric Legault [MVP - Outlook]

Coding it wouldn't be too hard, but you'd still have to build the logic to
determine where the folders are for 150 different contacts. So in the end it
may be just as easy to build all of those rules.

Regardless, there's a macro below to get you started.

However, I urge you to reconsider your filiing strategy. There's usually no
need for such a large hierarchy of folders. You can store everything in just
one folder (or a far smaller number of folders) and use views to create
logical distinctions between types of information. I would suggest using
Categories for the employee roles as a start. Then build one view for each
that restricts to items that have been tagged to that particular Category.

Another option, if all of the senders and recipients of these messages are
stored as Contacts, is to use the Activities tab on their Contact form. You
have to ensure that you use the Contacts button on e-mail messages, or use
the Actions menu from the Contact, to maintain these links so that they will
be displayed on that tab. You can also control which folders are searched
for these links from the Properties -> Activies tab for that Contacts folder.

Sub MoveMessagesFromCertainPeopleToSpecifiedFolder()
Dim objNS As Outlook.NameSpace
Dim objItem As Object, objInbox As Outlook.MAPIFolder
Dim objMessage As Outlook.MailItem, objDestinationFolder1 As
Outlook.MAPIFolder

Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)

For Each objItem In objInbox.Items
If objItem.Class = olmail Then
Set objMessage = objItem
'YOUR HOMEWORK IS TO GO TO:
'http://www.slipstick.com/dev/code/getsenderaddy.htm
'AND ADD CODE TO CHECK THE E-MAIL ADDRESS OF EACH MESSAGE IN THE
FOLDER
'TO SEE IF IT IS FROM THE PEOPLE THAT YOU ARE LOOKING FOR

'ALTERNATELY, YOU CAN USE THE FIND OR RESTRICT METHOD ON THE
ITEMS COLLECTION
'TO LOOK FOR SPECIFIC MESSAGES

'IF THIS IS THE PERSON, MOVE IT TO THE MySubFolder FOLDER IN
YOUR INBOX:
Set objDestinationFolder1 = objInbox.Folders("MySubFolder")
objMessage.Move objDestinationFolder1
End If
Next
End Sub
 
O

Onno Willems

Hi Eric,

Thanks for your reply!

I'm not sure I get (and want) your suggestion for storing things in a
reduced number of folders and using views. I will look into that, but the
current folder hierarchy I have is well thought out and actually a little
more complex than I described. And I like to have all conversations I had
with one person stored in a single folder which I can move around (for
example, moving it from an 'active' sub folder to a 'not-active' sub folder
for people who I no longer actively deal with, etc.

Thanks for the macro, this is indeed enough to get me started. I will look
into it and do my homework! ;-)

Thanks again,
Onno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top