[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

moving e-mail to folder - macro for Outlook 2003

Posted on 2011-09-24
7
Medium Priority
?
281 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Lost Word File? Eagerly, need it back? Read ahead; this File Recovery guide is for you.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
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…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

810 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