Reputation: 21
I want a VBA macro code for Outlook 2010 to move my manager requests mails from my inbox to another folder in case I reply.
Upvotes: 0
Views: 193
Reputation: 21
The following code is the answer. Thanks to Graham Mayor www.gmayor.com
It checks for messages from strAddress in the default Inbox and those that have been replied to are moved to the sub folder of Inbox defined as strFolder - here 'Test'.
If you want to check all messages then remove the lines marked '*
Sub MoveReplied()
Dim olItems As Outlook.Items
Dim olItem As Outlook.MailItem
Dim i As Long
Dim strFolder As String
Dim strAddress As String
strAddress = "someoneATsomewhere.com"
strFolder = "Test"
Set olItems = Session.GetDefaultFolder(olFolderInbox).Items
olItems.Sort "[Received]", True
For i = olItems.Count To 1 Step -1
Set olItem = olItems(i)
If olItem.SenderEmailAddress = strAddress Then '*****
If Not olItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10810003") = 0 Then
olItem.Move Session.GetDefaultFolder(olFolderInbox).folders(strFolder)
End If
End If '*****
Next i
Cleanup:
Set olItems = Nothing
Set olItem = Nothing
End Sub
Best regards =)
Upvotes: 1
Reputation: 5281
A rule really is the best solution for this, as @Bathsheba mentioned. Or, if you must do a VBA macro, I'd suggest recording a macro, then editing in VBA editor as required:
1. Click Tools, Macro.
2. Record macro.
Upvotes: 1