PDA

View Full Version : Macro to move based on sender to specific folder.



benmerrill
01-20-2014, 08:14 AM
Hi All,

I come to you for help.. I've dabbled just a bit with macros and have searched for days on this particular one. I ran out of rule space and I have 30+ people who send me emails daily. I'd like a macro that will allow me to run that will move the email based on the email address to that person's own folder. So essentially what a rule is already doing for me, but again I am out of rule space and cannot request additional space nor delete any previous rules at this time.

Any help would be greatly appreciated.

westconn1
01-21-2014, 05:02 AM
you can use the newmessage event to do this, so it is moved on arrival


Private Sub Application_NewMail()
Dim msg As MailItem, myfolder As MAPIFolder
Set myfolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set msg = myfolder.Items(myfolder.Items.Count) ' should get the newest file
fldr = msg.SenderName ' you can change this to any suitable property that can match your folder name
msg.Move myfolder.Folders(fldr) ' assumes that named folders are sub folders of inbox, or change to suit like
'msg.move myfolder.parent.folders(fldr)

End Sub

benmerrill
01-21-2014, 08:14 AM
you can use the newmessage event to do this, so it is moved on arrival


Private Sub Application_NewMail()
Dim msg As MailItem, myfolder As MAPIFolder
Set myfolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set msg = myfolder.Items(myfolder.Items.Count) ' should get the newest file
fldr = msg.SenderName ' you can change this to any suitable property that can match your folder name
msg.Move myfolder.Folders(fldr) ' assumes that named folders are sub folders of inbox, or change to suit like
'msg.move myfolder.parent.folders(fldr)

End Sub





Thank you for the help.. Where exactly do I put the email address from the person?

Thank you

westconn1
01-21-2014, 01:22 PM
Where exactly do I put the email address from the person?
i used sendername, which will either contain the email address or the address book name of the sender
depending on the structure of the folder name you may have to parse the email address, to return the exact folder name
if the folder name does not exist an error will occur on .Move, so you would need to check if the folder exists before calling .Move, in case you receive emails from senders who are not in your group of folders