Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Outlook Macro - Move read Messages

Posted on 2010-09-22
9
Medium Priority
?
559 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 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
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 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…

670 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