Outlook 2007 Macro: Move messages On Exit

Hello,

I need help writing a macro in Outlook 2007 that would move certain messages based on a certain sender from Inbox to another folder On Exit (i.e. once I close Outlook). Your help is appreciated.

Thanks.
maherusaAsked:
Who is Participating?
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Pending your response:

The snippet CRBQuit should be placed in a normal code module, the mailaccount name variable should reflect the sender of choice and the destfolder will need setting accordingly.  If the info is available I will happily assist with this.

To run the macro on close you need to put the
Private Sub Application_Quit()
    CRBQuit
End Sub

sub into the outlooksession code module.

Chris
Sub CRBQuit()
Const The_MailAccount_Name = "fred@fred.com"
Dim obj As Object
Dim mai As mailitem
Dim destFolder As Outlook.Folder
 
    Set destFolder = Application.Session.GetDefaultFolder(olFolderInbox).folders("experts Exchange")
    For Each obj In Application.Session.GetDefaultFolder(olFolderInbox).items
        If obj.Class = olMail Then
            Set mai = obj
            If mai.SenderEmailAddress = The_MailAccount_Name Then
                mai.Move destFolder
            End If
        End If
    Next
End Sub

Open in new window

0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Hello maherusa,

There is the Application_Quit event to run a macro.  All it requires is a sub to do the move ... in order to help with which what are the criteria for the mailmove ... addresses affected and directory for the move.

Private Sub Application_Quit()
'    OLQuit
End Sub

Regards,
Chris
0
 
maherusaAuthor Commented:
Hello Chris,

The move criteria is based on one single email address: from inbox to a directory folder (Note: using Exchange 2003 as the server).

Thanks.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Chris BottomleySoftware Quality Lead EngineerCommented:
By virtue of the macro this would be a client side operation, i.e. outlook.  WOuld you like me to draft something on that basis?

CHris
0
 
maherusaAuthor Commented:
Yes please.
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
WHat is the destination folderpath ... put the cursor on the folder in the explorer then type this in the VBE immediate window(ctrl + G to display):

?application.ActiveExplorer.CurrentFolder.FolderPath

Chris
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.