Hi...Any1 here who is good in outlook VBA.
I would like to a have a VBA which will find a string of text in the email and then put it into a folder.
I hope someone can give me some tips on how to do it.
Do you need VBA for such stuff ? Just create a mail rule that search for matching criteria in the mails and assign the action to move them to a folder.
As I need to select a partial string. Rules do not accept string in wildcard.
Eg.
023B extract 23 to folder 23
023A extract 23 to folder 23
123J extract 23 to folder 23
025A extract 25 to folder 25
225H extract 25 to folder 25
I only need the 2nd + 3rd string of text to move it to a folder. This information is store in the body of the message.
I have found this code which will search for the sender name and then put it into a folder. How do I make the changes and do a search in the body of the messages:-
Code:Sub MoveItems1() 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("aaaa").Folders("intake1") Set myItem = myItems.Find("[SenderName] = 'ABC COY'") While TypeName(myItem) <> "Nothing" myItem.Move myDestFolder Set myItem = myItems.FindNext Wend End Sub
Set myItem = myItems.Find("[SenderName] = 'ABC COY'")
Dim myItem As MailItem
Set myItem = myItems.GetFirst
While TypeName(myItem) <> "Nothing"
'You Can Access the mail's body using myItem.Body here
Set myItem = myItems.GetNext
Wend