Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Outlook Macro - Move read Messages

Posted on 2010-09-22
9
Medium Priority
?
563 Views
Last Modified: 2013-12-20
I need a Marco that will be able to move all read messages from my indox to another folder called read messages when I hit a certant key combination on the keyboard.   I have Outlook 2007,  I have read over many articles and blog posts on doing something similar to this but can never get it to work.  I am not that great with VBA Code to make sense of what is going on in the code I have come across to determin if it is what i need or not.  Most of the code I have come across does extra things that I do not need or is just a bit different than just a simple moving of read mail to a specific folder.

0
Comment
Question by:nck534
  • 5
  • 4
9 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 33742108
Hi, nck534.

Moving the messages is simple.  The code below should take care of that.  The key combination part is more of a problem.  The only way to run a macro via a key combination is to add a toolbar button or menu item that runs it and assign a hot key to it.  The hot keys that Outlook allows are limited and if the macro is available via a button, then I'm not sure I see the value in a hot key.
Sub MoveReadItems()
    Dim intIndex As Integer, olkItem As Object, olkInbox As Object, olkFolder As Object
    Set olkInbox = Session.GetDefaultFolder(olFolderInbox)
    'Assumes that the folder Read Messages is at the same level as the Inbox'
    Set olkFolder = Session.GetDefaultFolder(olFolderInbox).Parent.Folders("Read Messages")
    For intIndex = olkInbox.Items.count To 1 Step -1
        Set olkItem = olkInbox.Items(intIndex)
        If olkItem.UnRead = False Then
            olkItem.Move olkFolder
        End If
    Next
    Set olkItem = Nothing
    Set olkFolder = Nothing
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:nck534
ID: 33769563
Thank you for helping me out with this,  Where in this code will I put the name of the destination folder for read messages?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 33771175
Line #5.  As I mentioned in the comment I included in the code, the code assumes that the "Read Messages" folder is at the same level as the Inbox.  If the folder is at a different level, then the code on line #5 will have to be changed.
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 1

Author Comment

by:nck534
ID: 33771999
Works, Thank you for all of your help
0
 
LVL 76

Expert Comment

by:David Lee
ID: 33772194
You're welcome.  Glad I could help.
0
 
LVL 1

Author Comment

by:nck534
ID: 33809749
What would the code be on line #5 if the Read Messages folder was inside of the Inbox?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 33809785
If "Read Messages" is a folder under the inbox, the line #5 would look like this

Set olkFolder = Session.GetDefaultFolder(olFolderInbox).Folders("Read Messages")
0
 
LVL 1

Author Comment

by:nck534
ID: 33844304
Thanks it worked.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 33844399
You're welcome.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

926 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