Solved

Outlook Macro - Move read Messages

Posted on 2010-09-22
9
540 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 500 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
 
LVL 1

Author Comment

by:nck534
ID: 33771999
Works, Thank you for all of your help
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

706 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

20 Experts available now in Live!

Get 1:1 Help Now