Solved

moving e-mail to folder - macro for Outlook 2003

Posted on 2011-09-24
7
236 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Email signatures have numerous marketing benefits. Here are 8 top reasons to turn your email signature into a marketing channel.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now