Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to have a macro in Outlook 2007 to move selected items to sub-folders of my Inbox, marking them as unread as I go. This way I can assign buttons to move items quickly to my deal today and deal this week folders.

Many thanks,

Sam

share|improve this question

1 Answer 1

up vote 2 down vote accepted

I searched for this question on the site and on other places on the net and couldn't quickly come up with an easy answer, so have written the code myself. Here for the next person who wants to achieve this:

Option Explicit

Public Sub Today()

Dim myFolder As Folder

    Set myFolder = GetInboxSubFolder("* 0. Today")
    If Not myFolder Is Nothing Then
        MoveItemAndMarkAsUnread myFolder
    End If

End Sub

Private Function GetInboxSubFolder(folderName As String) As Folder

Dim myNamespace As NameSpace
Dim myInbox As Folder

    Set myNamespace = Application.GetNamespace("MAPI")
    Set myInbox = myNamespace.GetDefaultFolder(olFolderInbox)
    Set GetInboxSubFolder = myInbox.Folders(folderName)

End Function

Private Sub MoveItemAndMarkAsUnread(myFolder As Folder)

Dim myExplorer As Explorer
Dim mySelection As Selection

    Set myExplorer = Application.ActiveExplorer
    Set mySelection = myExplorer.Selection

Dim i As Integer
Dim myItem As MailItem

    For i = mySelection.Count To 1 Step -1

        mySelection.Item(i).UnRead = True
        mySelection.Item(i).Move myFolder

    Next i

End Sub

Hope that's useful to someone

share|improve this answer
    
Thanks! This helped me out this morning. –  Stuart Thompson Apr 30 '12 at 17:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.