Home » Questions » Computers [ Ask a new question ]

How do I write a macro in Outlook 2007 to move an item out of my Inbox to another folder and marke it as unread?

How do I write a macro in Outlook 2007 to move an item out of my Inbox to another folder and marke it as unread?

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.

Asked by: Guest | Views: 457
Total answers/comments: 2
bert [Entry]

"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"
Rfdbir [Entry]

cheap lipitor 40mg <a href="https://lipiws.top/">oral lipitor 40mg</a> buy atorvastatin 10mg pills