Solved

Outlook Macro - Move read Messages

Posted on 2010-09-22
9
549 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
[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
  • 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
SuperAntiSpyware Licenses Discounted by 25% !

Exclusive offer to Experts Exchange Members!
Buy SuperAntiSpyware License(s) from us and save 25% on the regular purchase price.
- Includes Full SuperAntiSpyware Vendor Support Entitlements
- Your Subscription does not begin until you activate your license
- Buy for your friends

 
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

Windows running painfully slow? Try these tips..

Stay away from Speed Up Computer Programs that do more harm than good.
Try these tips instead.
Step by step instructions in trouble shooting Windows Performance issues.

Question has a verified solution.

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

Suggested Solutions

Find out what you should include to make the best professional email signature for your organization.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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