?
Solved

moving e-mail to folder - macro for Outlook 2003

Posted on 2011-09-24
7
Medium Priority
?
277 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
Independent Software Vendors: 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 2000 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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 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