Solved

moving e-mail to folder - macro for Outlook 2003

Posted on 2011-09-24
7
252 Views
Last Modified: 2012-05-12
Hello
I need a macro which works as follows:

The macro checks if:
- the e-mail message(s) is not flagged
- the e-mail message(s) is read

if both conditions are met, then:
- if macro is executed from open e-mail message, the message is closed and e-mail is moved to folder "Work", subfolder "Processed"
- if macro is executed from e-mail folder then selected e-mails (one or more) are moved to folder "Work", subfolder "Processed"

if e-mail is unread or flagged, then nothing happens

The macro should work in Outlook 2003

thanks a lot!
Jarek
0
Comment
Question by:ja-rek
  • 4
  • 3
7 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 36594483
You don't talk about the folders parent but I assume below that it's the default inbox ...

Chris
Sub moveMail()
Dim mai As Object

    If TypeName(Application.ActiveWindow) = "Explorer" Then
        For Each mai In Application.ActiveExplorer.Selection
            movemailPayload mai
        Next
    ElseIf TypeName(Application.ActiveWindow) = "Inspector" Then
        movemailPayload Application.ActiveInspector.CurrentItem
    Else
        Exit Sub
    End If

End Sub

Sub movemailPayload(mai As MailItem)
    Stop
    If Not mai.UnRead Then Exit Sub
    If mai.FlagStatus <> olNoFlag Then Exit Sub
    mai.Move Application.Session.GetDefaultFolder(olFolderInbox).Folders("Work").Folders("Processed")
    
End Sub

Open in new window

0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 36594491
Apologies .... just realised I left the debug statement therein so ...

Chris
Sub moveMail()
Dim mai As Object

    If TypeName(Application.ActiveWindow) = "Explorer" Then
        For Each mai In Application.ActiveExplorer.Selection
            movemailPayload mai
        Next
    ElseIf TypeName(Application.ActiveWindow) = "Inspector" Then
        movemailPayload Application.ActiveInspector.CurrentItem
    Else
        Exit Sub
    End If

End Sub

Sub movemailPayload(mai As MailItem)
    If Not mai.UnRead Then Exit Sub
    If mai.FlagStatus <> olNoFlag Then Exit Sub
    mai.Move Application.Session.GetDefaultFolder(olFolderInbox).Folders("Work").Folders("Processed")
    
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:ja-rek
ID: 36594818
Dear Chris,
thank you very much, it works!
Can you please tell me if I can assign a shortcut key to this macro in Outlook 2003?
Or add it to some toolbar?
thanks once again,
Jarek

0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 36594857
0
 
LVL 1

Author Comment

by:ja-rek
ID: 36596003
Dear Chris,
can you please add another "if" in appropriate place in  moveMail() so that the the procedure is not ended when you select all items in a folder and among selected items you have not only emails but e.g. meeting invitations. such items should be skipped but the loop should continue.
thank you
Jarek
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 36596171
AS below
Sub moveMail()
Dim mai As Object

    If TypeName(Application.ActiveWindow) = "Explorer" Then
        For Each mai In Application.ActiveExplorer.Selection
            movemailPayload mai
        Next
    ElseIf TypeName(Application.ActiveWindow) = "Inspector" Then
        movemailPayload Application.ActiveInspector.CurrentItem
    Else
        Exit Sub
    End If

End Sub

Sub movemailPayload(mai As Object)
    Stop
    If TypeName(mai) <> "MailItem" Then Exit Sub
    If Not mai.UnRead Then Exit Sub
    If mai.FlagStatus <> olNoFlag Then Exit Sub
    mai.Move Application.Session.GetDefaultFolder(olFolderInbox).Folders("Work").Folders("Processed")
    
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:ja-rek
ID: 36602243
Dear Chris,
awesome!
I do appreciate your kind and professional help.
thank you very much.
Jarek
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question