Solved

moving e-mail to folder - macro for Outlook 2003

Posted on 2011-09-24
7
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 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