View Single Post
  #2  
Old September 29th 06, 11:34 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default Creating macro that will sort emails into folders based on text in

Here's some sample code that can move an e-mail to the folder you choose if
it contains the specified text in the message body:

Dim objMail As Outlook.MailItem

'Look for open item window
If ActiveInspector Is Nothing Then Exit Sub
'Look for open e-mails only
If ActiveInspector.CurrentItem.Class olMail Then Exit Sub
Set objMail = ActiveInspector.CurrentItem

If InStr(objMail.Body, "Look for this text") 0 Then
'will move to the folder you choose
Call objMail.Move(Application.GetNamespace("MAPI").Pick Folder)
'You can replace the above Move argument with a MAPIFolder object
directly instead of choosing one
'Use NameSpace.GetDefaultFolder to easily get a reference to a
default Outlook folder
If Err.Number 0 Then
'A folder wasn't chosen, or a non-email folder was chosen
End If
End If

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"mugginns" wrote:

I'm trying to find a good spot to find info on how to create a macro
that will basically look through the body of an email and sort it into
a folder based on finding a string, ie:

hospid= 102341

It would then be sent to a folder, ie:

hosp11

I'm a little new at programming for Outlook and was wondering if anyone
can help me out. I had looked at a post on outlookcode.com that
basically creates your own rules but i could not get this to work at
all, and I'm not sure if it was searching the body for the information
or not.

michael


Ads