PDA

View Full Version : Automatically Move E-mails to Folder.



Default616
02-21-2012, 09:51 AM
Im having a bit of difficultly modifing the following code... Any help would be greatly apprenticed!


I would like it search the body not the sendername. Also, whenever it runs it changes the time sent to the time of the macro was run. is there any way to change this.

Thanks!


Sub MoveItems()
Dim myolApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.MAPIFolder
Dim myDestFolder As Outlook.MAPIFolder
Dim myItems As Outlook.Items
Dim myItem As Object
Set myNameSpace = myolApp.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myItems = myInbox.Items
Set myDestFolder = myInbox.Folders("Personal Mail")
Set myItem = myItems.Find("[SenderName] = 'Kyle C'")
While TypeName(myItem) <> "Nothing"
myItem.Move myDestFolder
Set myItem = myItems.FindNext
Wend
End Sub

JP2112
02-23-2012, 02:15 PM
Unfortunately the Items.Find Method cannot be used on the email body:

http://msdn.microsoft.com/en-us/library/aa220093(v=office.11).aspx