• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 464
  • Last Modified:

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.
0
maherusa
Asked:
maherusa
  • 4
  • 2
1 Solution
 
Chris BottomleyCommented:
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
 
Chris BottomleyCommented:
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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
maherusaAuthor Commented:
Yes please.
0
 
Chris BottomleyCommented:
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
 
Chris BottomleyCommented:
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

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now